From 50a266e064abe8460e477f62df34373c489f64cd Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Tue, 29 Aug 2023 05:11:22 +1200 Subject: [PATCH] feat: Add Seamless to Inpaint & Outpaint --- .../graphBuilders/buildCanvasInpaintGraph.ts | 26 ++++++++---- .../graphBuilders/buildCanvasOutpaintGraph.ts | 26 ++++++++---- .../buildCanvasSDXLInpaintGraph.ts | 41 ++++++++++++++----- .../buildCanvasSDXLOutpaintGraph.ts | 25 +++++++++-- 4 files changed, 90 insertions(+), 28 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts index b4e974dadd..6eafd1fc06 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts @@ -13,6 +13,7 @@ import { import { addControlNetToLinearGraph } from './addControlNetToLinearGraph'; import { addLoRAsToGraph } from './addLoRAsToGraph'; import { addNSFWCheckerToGraph } from './addNSFWCheckerToGraph'; +import { addSeamlessToLinearGraph } from './addSeamlessToLinearGraph'; import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { @@ -38,6 +39,7 @@ import { POSITIVE_CONDITIONING, RANDOM_INT, RANGE_OF_SIZE, + SEAMLESS, } from './constants'; /** @@ -68,6 +70,8 @@ export const buildCanvasInpaintGraph = ( canvasCoherenceSteps, canvasCoherenceStrength, clipSkip, + seamlessXAxis, + seamlessYAxis, } = state.generation; if (!model) { @@ -85,6 +89,8 @@ export const buildCanvasInpaintGraph = ( shouldAutoSave, } = state.canvas; + let modelLoaderNodeId = MAIN_MODEL_LOADER; + const use_cpu = shouldUseNoiseSettings ? shouldUseCpuNoise : shouldUseCpuNoise; @@ -92,9 +98,9 @@ export const buildCanvasInpaintGraph = ( const graph: NonNullableGraph = { id: CANVAS_INPAINT_GRAPH, nodes: { - [MAIN_MODEL_LOADER]: { + [modelLoaderNodeId]: { type: 'main_model_loader', - id: MAIN_MODEL_LOADER, + id: modelLoaderNodeId, is_intermediate: true, model, }, @@ -204,7 +210,7 @@ export const buildCanvasInpaintGraph = ( // Connect Model Loader to CLIP Skip and UNet { source: { - node_id: MAIN_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -214,7 +220,7 @@ export const buildCanvasInpaintGraph = ( }, { source: { - node_id: MAIN_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'clip', }, destination: { @@ -349,7 +355,7 @@ export const buildCanvasInpaintGraph = ( }, { source: { - node_id: MAIN_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -595,11 +601,17 @@ export const buildCanvasInpaintGraph = ( (graph.nodes[RANGE_OF_SIZE] as RangeOfSizeInvocation).start = seed; } + // Add Seamless To Graph + if (seamlessXAxis || seamlessYAxis) { + addSeamlessToLinearGraph(state, graph, modelLoaderNodeId); + modelLoaderNodeId = SEAMLESS; + } + // Add VAE - addVAEToGraph(state, graph, MAIN_MODEL_LOADER); + addVAEToGraph(state, graph, modelLoaderNodeId); // add LoRA support - addLoRAsToGraph(state, graph, DENOISE_LATENTS, MAIN_MODEL_LOADER); + addLoRAsToGraph(state, graph, DENOISE_LATENTS, modelLoaderNodeId); // add controlnet, mutating `graph` addControlNetToLinearGraph(state, graph, DENOISE_LATENTS); diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasOutpaintGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasOutpaintGraph.ts index 8916dd0652..aec9d1c035 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasOutpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasOutpaintGraph.ts @@ -14,6 +14,7 @@ import { import { addControlNetToLinearGraph } from './addControlNetToLinearGraph'; import { addLoRAsToGraph } from './addLoRAsToGraph'; import { addNSFWCheckerToGraph } from './addNSFWCheckerToGraph'; +import { addSeamlessToLinearGraph } from './addSeamlessToLinearGraph'; import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { @@ -43,6 +44,7 @@ import { POSITIVE_CONDITIONING, RANDOM_INT, RANGE_OF_SIZE, + SEAMLESS, } from './constants'; /** @@ -75,6 +77,8 @@ export const buildCanvasOutpaintGraph = ( tileSize, infillMethod, clipSkip, + seamlessXAxis, + seamlessYAxis, } = state.generation; if (!model) { @@ -92,6 +96,8 @@ export const buildCanvasOutpaintGraph = ( shouldAutoSave, } = state.canvas; + let modelLoaderNodeId = MAIN_MODEL_LOADER; + const use_cpu = shouldUseNoiseSettings ? shouldUseCpuNoise : shouldUseCpuNoise; @@ -99,9 +105,9 @@ export const buildCanvasOutpaintGraph = ( const graph: NonNullableGraph = { id: CANVAS_OUTPAINT_GRAPH, nodes: { - [MAIN_MODEL_LOADER]: { + [modelLoaderNodeId]: { type: 'main_model_loader', - id: MAIN_MODEL_LOADER, + id: modelLoaderNodeId, is_intermediate: true, model, }, @@ -222,7 +228,7 @@ export const buildCanvasOutpaintGraph = ( // Connect Model Loader To UNet & Clip Skip { source: { - node_id: MAIN_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -232,7 +238,7 @@ export const buildCanvasOutpaintGraph = ( }, { source: { - node_id: MAIN_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'clip', }, destination: { @@ -389,7 +395,7 @@ export const buildCanvasOutpaintGraph = ( }, { source: { - node_id: MAIN_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -732,11 +738,17 @@ export const buildCanvasOutpaintGraph = ( (graph.nodes[RANGE_OF_SIZE] as RangeOfSizeInvocation).start = seed; } + // Add Seamless To Graph + if (seamlessXAxis || seamlessYAxis) { + addSeamlessToLinearGraph(state, graph, modelLoaderNodeId); + modelLoaderNodeId = SEAMLESS; + } + // Add VAE - addVAEToGraph(state, graph, MAIN_MODEL_LOADER); + addVAEToGraph(state, graph, modelLoaderNodeId); // add LoRA support - addLoRAsToGraph(state, graph, DENOISE_LATENTS, MAIN_MODEL_LOADER); + addLoRAsToGraph(state, graph, DENOISE_LATENTS, modelLoaderNodeId); // add controlnet, mutating `graph` addControlNetToLinearGraph(state, graph, DENOISE_LATENTS); diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLInpaintGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLInpaintGraph.ts index f51c2444d4..4b2ffdb7ca 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLInpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLInpaintGraph.ts @@ -14,6 +14,7 @@ import { addControlNetToLinearGraph } from './addControlNetToLinearGraph'; import { addNSFWCheckerToGraph } from './addNSFWCheckerToGraph'; import { addSDXLLoRAsToGraph } from './addSDXLLoRAstoGraph'; import { addSDXLRefinerToGraph } from './addSDXLRefinerToGraph'; +import { addSeamlessToLinearGraph } from './addSeamlessToLinearGraph'; import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { @@ -35,9 +36,11 @@ import { POSITIVE_CONDITIONING, RANDOM_INT, RANGE_OF_SIZE, + REFINER_SEAMLESS, SDXL_CANVAS_INPAINT_GRAPH, SDXL_DENOISE_LATENTS, SDXL_MODEL_LOADER, + SEAMLESS, } from './constants'; import { craftSDXLStylePrompt } from './helpers/craftSDXLStylePrompt'; @@ -67,6 +70,8 @@ export const buildCanvasSDXLInpaintGraph = ( maskBlurMethod, canvasCoherenceSteps, canvasCoherenceStrength, + seamlessXAxis, + seamlessYAxis, } = state.generation; const { @@ -91,6 +96,8 @@ export const buildCanvasSDXLInpaintGraph = ( shouldAutoSave, } = state.canvas; + let modelLoaderNodeId = SDXL_MODEL_LOADER; + const use_cpu = shouldUseNoiseSettings ? shouldUseCpuNoise : shouldUseCpuNoise; @@ -102,9 +109,9 @@ export const buildCanvasSDXLInpaintGraph = ( const graph: NonNullableGraph = { id: SDXL_CANVAS_INPAINT_GRAPH, nodes: { - [SDXL_MODEL_LOADER]: { + [modelLoaderNodeId]: { type: 'sdxl_model_loader', - id: SDXL_MODEL_LOADER, + id: modelLoaderNodeId, model, }, [POSITIVE_CONDITIONING]: { @@ -209,7 +216,7 @@ export const buildCanvasSDXLInpaintGraph = ( // Connect Model Loader to UNet and CLIP { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -219,7 +226,7 @@ export const buildCanvasSDXLInpaintGraph = ( }, { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'clip', }, destination: { @@ -229,7 +236,7 @@ export const buildCanvasSDXLInpaintGraph = ( }, { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'clip2', }, destination: { @@ -239,7 +246,7 @@ export const buildCanvasSDXLInpaintGraph = ( }, { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'clip', }, destination: { @@ -249,7 +256,7 @@ export const buildCanvasSDXLInpaintGraph = ( }, { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'clip2', }, destination: { @@ -363,7 +370,7 @@ export const buildCanvasSDXLInpaintGraph = ( }, { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -609,16 +616,28 @@ export const buildCanvasSDXLInpaintGraph = ( (graph.nodes[RANGE_OF_SIZE] as RangeOfSizeInvocation).start = seed; } + // Add Seamless To Graph + if (seamlessXAxis || seamlessYAxis) { + addSeamlessToLinearGraph(state, graph, modelLoaderNodeId); + modelLoaderNodeId = SEAMLESS; + } + // Add Refiner if enabled if (shouldUseSDXLRefiner) { - addSDXLRefinerToGraph(state, graph, CANVAS_COHERENCE_DENOISE_LATENTS); + addSDXLRefinerToGraph( + state, + graph, + CANVAS_COHERENCE_DENOISE_LATENTS, + modelLoaderNodeId + ); + modelLoaderNodeId = REFINER_SEAMLESS; } // optionally add custom VAE - addVAEToGraph(state, graph, SDXL_MODEL_LOADER); + addVAEToGraph(state, graph, modelLoaderNodeId); // add LoRA support - addSDXLLoRAsToGraph(state, graph, SDXL_DENOISE_LATENTS, SDXL_MODEL_LOADER); + addSDXLLoRAsToGraph(state, graph, SDXL_DENOISE_LATENTS, modelLoaderNodeId); // add controlnet, mutating `graph` addControlNetToLinearGraph(state, graph, SDXL_DENOISE_LATENTS); diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLOutpaintGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLOutpaintGraph.ts index 05432f0274..0c075beb4a 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLOutpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLOutpaintGraph.ts @@ -15,6 +15,7 @@ import { addControlNetToLinearGraph } from './addControlNetToLinearGraph'; import { addNSFWCheckerToGraph } from './addNSFWCheckerToGraph'; import { addSDXLLoRAsToGraph } from './addSDXLLoRAstoGraph'; import { addSDXLRefinerToGraph } from './addSDXLRefinerToGraph'; +import { addSeamlessToLinearGraph } from './addSeamlessToLinearGraph'; import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { @@ -40,9 +41,11 @@ import { POSITIVE_CONDITIONING, RANDOM_INT, RANGE_OF_SIZE, + REFINER_SEAMLESS, SDXL_CANVAS_OUTPAINT_GRAPH, SDXL_DENOISE_LATENTS, SDXL_MODEL_LOADER, + SEAMLESS, } from './constants'; import { craftSDXLStylePrompt } from './helpers/craftSDXLStylePrompt'; @@ -74,6 +77,8 @@ export const buildCanvasSDXLOutpaintGraph = ( canvasCoherenceStrength, tileSize, infillMethod, + seamlessXAxis, + seamlessYAxis, } = state.generation; const { @@ -98,6 +103,8 @@ export const buildCanvasSDXLOutpaintGraph = ( shouldAutoSave, } = state.canvas; + let modelLoaderNodeId = SDXL_MODEL_LOADER; + const use_cpu = shouldUseNoiseSettings ? shouldUseCpuNoise : shouldUseCpuNoise; @@ -747,16 +754,28 @@ export const buildCanvasSDXLOutpaintGraph = ( (graph.nodes[RANGE_OF_SIZE] as RangeOfSizeInvocation).start = seed; } + // Add Seamless To Graph + if (seamlessXAxis || seamlessYAxis) { + addSeamlessToLinearGraph(state, graph, modelLoaderNodeId); + modelLoaderNodeId = SEAMLESS; + } + // Add Refiner if enabled if (shouldUseSDXLRefiner) { - addSDXLRefinerToGraph(state, graph, CANVAS_COHERENCE_DENOISE_LATENTS); + addSDXLRefinerToGraph( + state, + graph, + CANVAS_COHERENCE_DENOISE_LATENTS, + modelLoaderNodeId + ); + modelLoaderNodeId = REFINER_SEAMLESS; } // optionally add custom VAE - addVAEToGraph(state, graph, SDXL_MODEL_LOADER); + addVAEToGraph(state, graph, modelLoaderNodeId); // add LoRA support - addSDXLLoRAsToGraph(state, graph, SDXL_DENOISE_LATENTS, SDXL_MODEL_LOADER); + addSDXLLoRAsToGraph(state, graph, SDXL_DENOISE_LATENTS, modelLoaderNodeId); // add controlnet, mutating `graph` addControlNetToLinearGraph(state, graph, SDXL_DENOISE_LATENTS);