From 7a295cbfd5be2f74804c1b35692219d5603d89ba Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:20:45 +1200 Subject: [PATCH] experimental: Pass Mask To Coherence Pass --- .../graphBuilders/addSDXLRefinerToGraph.ts | 5 +- .../nodes/util/graphBuilders/addVAEToGraph.ts | 11 +++ .../graphBuilders/buildCanvasInpaintGraph.ts | 89 ++++++++++++++++-- .../graphBuilders/buildCanvasOutpaintGraph.ts | 87 ++++++++++++++---- .../buildCanvasSDXLInpaintGraph.ts | 77 +++++++++++++++- .../buildCanvasSDXLOutpaintGraph.ts | 92 ++++++++++++++----- .../nodes/util/graphBuilders/constants.ts | 4 + .../frontend/web/src/services/api/types.ts | 1 + 8 files changed, 313 insertions(+), 53 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addSDXLRefinerToGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addSDXLRefinerToGraph.ts index 92d15ffd8c..c9b055dfc2 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addSDXLRefinerToGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addSDXLRefinerToGraph.ts @@ -10,7 +10,8 @@ import { CANVAS_OUTPUT, INPAINT_IMAGE_RESIZE_UP, LATENTS_TO_IMAGE, - MASK_BLUR, + MASK_COMBINE, + MASK_RESIZE_UP, METADATA_ACCUMULATOR, SDXL_CANVAS_IMAGE_TO_IMAGE_GRAPH, SDXL_CANVAS_INPAINT_GRAPH, @@ -257,7 +258,7 @@ export const addSDXLRefinerToGraph = ( graph.edges.push( { source: { - node_id: MASK_BLUR, + node_id: isUsingScaledDimensions ? MASK_RESIZE_UP : MASK_COMBINE, field: 'image', }, destination: { diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts index b274f8fbba..34d37e9b17 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts @@ -2,6 +2,7 @@ import { RootState } from 'app/store/store'; import { NonNullableGraph } from 'features/nodes/types/types'; import { MetadataAccumulatorInvocation } from 'services/api/types'; import { + CANVAS_COHERENCE_INPAINT_CREATE_MASK, CANVAS_IMAGE_TO_IMAGE_GRAPH, CANVAS_INPAINT_GRAPH, CANVAS_OUTPAINT_GRAPH, @@ -135,6 +136,16 @@ export const addVAEToGraph = ( field: 'vae', }, }, + { + source: { + node_id: isAutoVae ? modelLoaderNodeId : VAE_LOADER, + field: isAutoVae && isOnnxModel ? 'vae_decoder' : 'vae', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'vae', + }, + }, { source: { node_id: isAutoVae ? modelLoaderNodeId : VAE_LOADER, 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 6eafd1fc06..1783174079 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts @@ -6,6 +6,7 @@ import { ImageBlurInvocation, ImageDTO, ImageToLatentsInvocation, + MaskEdgeInvocation, NoiseInvocation, RandomIntInvocation, RangeOfSizeInvocation, @@ -18,6 +19,8 @@ import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { CANVAS_COHERENCE_DENOISE_LATENTS, + CANVAS_COHERENCE_INPAINT_CREATE_MASK, + CANVAS_COHERENCE_MASK_EDGE, CANVAS_COHERENCE_NOISE, CANVAS_COHERENCE_NOISE_INCREMENT, CANVAS_INPAINT_GRAPH, @@ -89,6 +92,10 @@ export const buildCanvasInpaintGraph = ( shouldAutoSave, } = state.canvas; + const isUsingScaledDimensions = ['auto', 'manual'].includes( + boundingBoxScaleMethod + ); + let modelLoaderNodeId = MAIN_MODEL_LOADER; const use_cpu = shouldUseNoiseSettings @@ -135,18 +142,18 @@ export const buildCanvasInpaintGraph = ( is_intermediate: true, fp32: vaePrecision === 'fp32' ? true : false, }, - [INPAINT_CREATE_MASK]: { - type: 'create_denoise_mask', - id: INPAINT_CREATE_MASK, - is_intermediate: true, - fp32: vaePrecision === 'fp32' ? true : false, - }, [NOISE]: { type: 'noise', id: NOISE, use_cpu, is_intermediate: true, }, + [INPAINT_CREATE_MASK]: { + type: 'create_denoise_mask', + id: INPAINT_CREATE_MASK, + is_intermediate: true, + fp32: vaePrecision === 'fp32' ? true : false, + }, [DENOISE_LATENTS]: { type: 'denoise_latents', id: DENOISE_LATENTS, @@ -169,9 +176,24 @@ export const buildCanvasInpaintGraph = ( b: 1, is_intermediate: true, }, + [CANVAS_COHERENCE_MASK_EDGE]: { + type: 'mask_edge', + id: CANVAS_COHERENCE_MASK_EDGE, + is_intermediate: true, + edge_blur: maskBlur, + edge_size: maskBlur * 2, + low_threshold: 100, + high_threshold: 200, + }, + [CANVAS_COHERENCE_INPAINT_CREATE_MASK]: { + type: 'create_denoise_mask', + id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + is_intermediate: true, + fp32: vaePrecision === 'fp32' ? true : false, + }, [CANVAS_COHERENCE_DENOISE_LATENTS]: { type: 'denoise_latents', - id: DENOISE_LATENTS, + id: CANVAS_COHERENCE_DENOISE_LATENTS, is_intermediate: true, steps: canvasCoherenceSteps, cfg_scale: cfg_scale, @@ -311,6 +333,27 @@ export const buildCanvasInpaintGraph = ( field: 'denoise_mask', }, }, + // Create Coherence Mask + { + source: { + node_id: CANVAS_COHERENCE_MASK_EDGE, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'mask', + }, + }, + { + source: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'denoise_mask', + }, + destination: { + node_id: CANVAS_COHERENCE_DENOISE_LATENTS, + field: 'denoise_mask', + }, + }, // Iterate { source: { @@ -418,7 +461,7 @@ export const buildCanvasInpaintGraph = ( }; // Handle Scale Before Processing - if (['auto', 'manual'].includes(boundingBoxScaleMethod)) { + if (isUsingScaledDimensions) { const scaledWidth: number = scaledBoundingBoxDimensions.width; const scaledHeight: number = scaledBoundingBoxDimensions.height; @@ -494,6 +537,26 @@ export const buildCanvasInpaintGraph = ( field: 'image', }, }, + { + source: { + node_id: INPAINT_IMAGE_RESIZE_UP, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'image', + }, + }, + { + source: { + node_id: MASK_RESIZE_UP, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_MASK_EDGE, + field: 'image', + }, + }, // Color Correct The Inpainted Result { source: { @@ -555,6 +618,16 @@ export const buildCanvasInpaintGraph = ( ...(graph.nodes[INPAINT_CREATE_MASK] as CreateDenoiseMaskInvocation), image: canvasInitImage, }; + graph.nodes[CANVAS_COHERENCE_INPAINT_CREATE_MASK] = { + ...(graph.nodes[ + CANVAS_COHERENCE_INPAINT_CREATE_MASK + ] as CreateDenoiseMaskInvocation), + image: canvasInitImage, + }; + graph.nodes[CANVAS_COHERENCE_MASK_EDGE] = { + ...(graph.nodes[CANVAS_COHERENCE_MASK_EDGE] as MaskEdgeInvocation), + image: canvasMaskImage, + }; graph.edges.push( // Color Correct The Inpainted Result 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 aec9d1c035..2098d3c3e1 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasOutpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasOutpaintGraph.ts @@ -2,7 +2,6 @@ import { logger } from 'app/logging/logger'; import { RootState } from 'app/store/store'; import { NonNullableGraph } from 'features/nodes/types/types'; import { - ImageBlurInvocation, ImageDTO, ImageToLatentsInvocation, InfillPatchMatchInvocation, @@ -19,6 +18,8 @@ import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { CANVAS_COHERENCE_DENOISE_LATENTS, + CANVAS_COHERENCE_INPAINT_CREATE_MASK, + CANVAS_COHERENCE_MASK_EDGE, CANVAS_COHERENCE_NOISE, CANVAS_COHERENCE_NOISE_INCREMENT, CANVAS_OUTPAINT_GRAPH, @@ -34,7 +35,6 @@ import { ITERATE, LATENTS_TO_IMAGE, MAIN_MODEL_LOADER, - MASK_BLUR, MASK_COMBINE, MASK_FROM_ALPHA, MASK_RESIZE_DOWN, @@ -71,7 +71,6 @@ export const buildCanvasOutpaintGraph = ( shouldUseNoiseSettings, shouldUseCpuNoise, maskBlur, - maskBlurMethod, canvasCoherenceSteps, canvasCoherenceStrength, tileSize, @@ -96,6 +95,10 @@ export const buildCanvasOutpaintGraph = ( shouldAutoSave, } = state.canvas; + const isUsingScaledDimensions = ['auto', 'manual'].includes( + boundingBoxScaleMethod + ); + let modelLoaderNodeId = MAIN_MODEL_LOADER; const use_cpu = shouldUseNoiseSettings @@ -141,13 +144,6 @@ export const buildCanvasOutpaintGraph = ( is_intermediate: true, mask2: canvasMaskImage, }, - [MASK_BLUR]: { - type: 'img_blur', - id: MASK_BLUR, - is_intermediate: true, - radius: maskBlur, - blur_type: maskBlurMethod, - }, [INPAINT_IMAGE]: { type: 'i2l', id: INPAINT_IMAGE, @@ -188,6 +184,21 @@ export const buildCanvasOutpaintGraph = ( b: 1, is_intermediate: true, }, + [CANVAS_COHERENCE_MASK_EDGE]: { + type: 'mask_edge', + id: CANVAS_COHERENCE_MASK_EDGE, + is_intermediate: true, + edge_blur: maskBlur, + edge_size: maskBlur * 2, + low_threshold: 100, + high_threshold: 200, + }, + [CANVAS_COHERENCE_INPAINT_CREATE_MASK]: { + type: 'create_denoise_mask', + id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + is_intermediate: true, + fp32: vaePrecision === 'fp32' ? true : false, + }, [CANVAS_COHERENCE_DENOISE_LATENTS]: { type: 'denoise_latents', id: CANVAS_COHERENCE_DENOISE_LATENTS, @@ -333,7 +344,7 @@ export const buildCanvasOutpaintGraph = ( // Create Inpaint Mask { source: { - node_id: MASK_BLUR, + node_id: isUsingScaledDimensions ? MASK_RESIZE_UP : MASK_COMBINE, field: 'image', }, destination: { @@ -351,6 +362,27 @@ export const buildCanvasOutpaintGraph = ( field: 'denoise_mask', }, }, + // Create Coherence Mask + { + source: { + node_id: CANVAS_COHERENCE_MASK_EDGE, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'mask', + }, + }, + { + source: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'denoise_mask', + }, + destination: { + node_id: CANVAS_COHERENCE_DENOISE_LATENTS, + field: 'denoise_mask', + }, + }, // Iterate { source: { @@ -484,7 +516,7 @@ export const buildCanvasOutpaintGraph = ( } // Handle Scale Before Processing - if (['auto', 'manual'].includes(boundingBoxScaleMethod)) { + if (isUsingScaledDimensions) { const scaledWidth: number = scaledBoundingBoxDimensions.width; const scaledHeight: number = scaledBoundingBoxDimensions.height; @@ -556,6 +588,16 @@ export const buildCanvasOutpaintGraph = ( field: 'image', }, }, + { + source: { + node_id: INPAINT_INFILL, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'image', + }, + }, // Take combined mask and resize and then blur { source: { @@ -573,7 +615,7 @@ export const buildCanvasOutpaintGraph = ( field: 'image', }, destination: { - node_id: MASK_BLUR, + node_id: CANVAS_COHERENCE_MASK_EDGE, field: 'image', }, }, @@ -658,19 +700,26 @@ export const buildCanvasOutpaintGraph = ( ...(graph.nodes[INPAINT_IMAGE] as ImageToLatentsInvocation), image: canvasInitImage, }; - graph.nodes[MASK_BLUR] = { - ...(graph.nodes[MASK_BLUR] as ImageBlurInvocation), - }; graph.edges.push( // Take combined mask and plug it to blur + { + source: { + node_id: INPAINT_INFILL, + field: 'image', + }, + destination: { + node_id: INPAINT_CREATE_MASK, + field: 'image', + }, + }, { source: { node_id: MASK_COMBINE, field: 'image', }, destination: { - node_id: MASK_BLUR, + node_id: CANVAS_COHERENCE_MASK_EDGE, field: 'image', }, }, @@ -680,7 +729,7 @@ export const buildCanvasOutpaintGraph = ( field: 'image', }, destination: { - node_id: INPAINT_CREATE_MASK, + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, field: 'image', }, }, @@ -707,7 +756,7 @@ export const buildCanvasOutpaintGraph = ( }, { source: { - node_id: MASK_BLUR, + node_id: MASK_COMBINE, field: 'image', }, destination: { 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 3cf1eb41e8..ca3f39257e 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLInpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLInpaintGraph.ts @@ -6,6 +6,7 @@ import { ImageBlurInvocation, ImageDTO, ImageToLatentsInvocation, + MaskEdgeInvocation, NoiseInvocation, RandomIntInvocation, RangeOfSizeInvocation, @@ -19,6 +20,8 @@ import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { CANVAS_COHERENCE_DENOISE_LATENTS, + CANVAS_COHERENCE_INPAINT_CREATE_MASK, + CANVAS_COHERENCE_MASK_EDGE, CANVAS_COHERENCE_NOISE, CANVAS_COHERENCE_NOISE_INCREMENT, CANVAS_OUTPUT, @@ -96,6 +99,10 @@ export const buildCanvasSDXLInpaintGraph = ( shouldAutoSave, } = state.canvas; + const isUsingScaledDimensions = ['auto', 'manual'].includes( + boundingBoxScaleMethod + ); + let modelLoaderNodeId = SDXL_MODEL_LOADER; const use_cpu = shouldUseNoiseSettings @@ -175,9 +182,24 @@ export const buildCanvasSDXLInpaintGraph = ( b: 1, is_intermediate: true, }, + [CANVAS_COHERENCE_MASK_EDGE]: { + type: 'mask_edge', + id: CANVAS_COHERENCE_MASK_EDGE, + is_intermediate: true, + edge_blur: maskBlur, + edge_size: maskBlur * 2, + low_threshold: 100, + high_threshold: 200, + }, + [CANVAS_COHERENCE_INPAINT_CREATE_MASK]: { + type: 'create_denoise_mask', + id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + is_intermediate: true, + fp32: vaePrecision === 'fp32' ? true : false, + }, [CANVAS_COHERENCE_DENOISE_LATENTS]: { type: 'denoise_latents', - id: SDXL_DENOISE_LATENTS, + id: CANVAS_COHERENCE_DENOISE_LATENTS, is_intermediate: true, steps: canvasCoherenceSteps, cfg_scale: cfg_scale, @@ -326,6 +348,27 @@ export const buildCanvasSDXLInpaintGraph = ( field: 'denoise_mask', }, }, + // Create Coherence Mask + { + source: { + node_id: CANVAS_COHERENCE_MASK_EDGE, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'mask', + }, + }, + { + source: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'denoise_mask', + }, + destination: { + node_id: CANVAS_COHERENCE_DENOISE_LATENTS, + field: 'denoise_mask', + }, + }, // Iterate { source: { @@ -433,7 +476,7 @@ export const buildCanvasSDXLInpaintGraph = ( }; // Handle Scale Before Processing - if (['auto', 'manual'].includes(boundingBoxScaleMethod)) { + if (isUsingScaledDimensions) { const scaledWidth: number = scaledBoundingBoxDimensions.width; const scaledHeight: number = scaledBoundingBoxDimensions.height; @@ -509,6 +552,26 @@ export const buildCanvasSDXLInpaintGraph = ( field: 'image', }, }, + { + source: { + node_id: INPAINT_IMAGE_RESIZE_UP, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'image', + }, + }, + { + source: { + node_id: MASK_RESIZE_UP, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_MASK_EDGE, + field: 'image', + }, + }, // Color Correct The Inpainted Result { source: { @@ -570,6 +633,16 @@ export const buildCanvasSDXLInpaintGraph = ( ...(graph.nodes[INPAINT_CREATE_MASK] as CreateDenoiseMaskInvocation), image: canvasInitImage, }; + graph.nodes[CANVAS_COHERENCE_INPAINT_CREATE_MASK] = { + ...(graph.nodes[ + CANVAS_COHERENCE_INPAINT_CREATE_MASK + ] as CreateDenoiseMaskInvocation), + image: canvasInitImage, + }; + graph.nodes[CANVAS_COHERENCE_MASK_EDGE] = { + ...(graph.nodes[CANVAS_COHERENCE_MASK_EDGE] as MaskEdgeInvocation), + image: canvasMaskImage, + }; graph.edges.push( // Color Correct The Inpainted Result 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 811efce6df..e8c3ce6435 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLOutpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasSDXLOutpaintGraph.ts @@ -2,7 +2,6 @@ import { logger } from 'app/logging/logger'; import { RootState } from 'app/store/store'; import { NonNullableGraph } from 'features/nodes/types/types'; import { - ImageBlurInvocation, ImageDTO, ImageToLatentsInvocation, InfillPatchMatchInvocation, @@ -20,6 +19,8 @@ import { addVAEToGraph } from './addVAEToGraph'; import { addWatermarkerToGraph } from './addWatermarkerToGraph'; import { CANVAS_COHERENCE_DENOISE_LATENTS, + CANVAS_COHERENCE_INPAINT_CREATE_MASK, + CANVAS_COHERENCE_MASK_EDGE, CANVAS_COHERENCE_NOISE, CANVAS_COHERENCE_NOISE_INCREMENT, CANVAS_OUTPUT, @@ -31,7 +32,6 @@ import { INPAINT_INFILL_RESIZE_DOWN, ITERATE, LATENTS_TO_IMAGE, - MASK_BLUR, MASK_COMBINE, MASK_FROM_ALPHA, MASK_RESIZE_DOWN, @@ -72,7 +72,6 @@ export const buildCanvasSDXLOutpaintGraph = ( shouldUseNoiseSettings, shouldUseCpuNoise, maskBlur, - maskBlurMethod, canvasCoherenceSteps, canvasCoherenceStrength, tileSize, @@ -103,6 +102,10 @@ export const buildCanvasSDXLOutpaintGraph = ( shouldAutoSave, } = state.canvas; + const isUsingScaledDimensions = ['auto', 'manual'].includes( + boundingBoxScaleMethod + ); + let modelLoaderNodeId = SDXL_MODEL_LOADER; const use_cpu = shouldUseNoiseSettings @@ -145,13 +148,6 @@ export const buildCanvasSDXLOutpaintGraph = ( is_intermediate: true, mask2: canvasMaskImage, }, - [MASK_BLUR]: { - type: 'img_blur', - id: MASK_BLUR, - is_intermediate: true, - radius: maskBlur, - blur_type: maskBlurMethod, - }, [INPAINT_IMAGE]: { type: 'i2l', id: INPAINT_IMAGE, @@ -194,6 +190,21 @@ export const buildCanvasSDXLOutpaintGraph = ( b: 1, is_intermediate: true, }, + [CANVAS_COHERENCE_MASK_EDGE]: { + type: 'mask_edge', + id: CANVAS_COHERENCE_MASK_EDGE, + is_intermediate: true, + edge_blur: maskBlur, + edge_size: maskBlur * 2, + low_threshold: 100, + high_threshold: 200, + }, + [CANVAS_COHERENCE_INPAINT_CREATE_MASK]: { + type: 'create_denoise_mask', + id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + is_intermediate: true, + fp32: vaePrecision === 'fp32' ? true : false, + }, [CANVAS_COHERENCE_DENOISE_LATENTS]: { type: 'denoise_latents', id: CANVAS_COHERENCE_DENOISE_LATENTS, @@ -348,7 +359,7 @@ export const buildCanvasSDXLOutpaintGraph = ( // Create Inpaint Mask { source: { - node_id: MASK_BLUR, + node_id: isUsingScaledDimensions ? MASK_RESIZE_UP : MASK_COMBINE, field: 'image', }, destination: { @@ -366,6 +377,27 @@ export const buildCanvasSDXLOutpaintGraph = ( field: 'denoise_mask', }, }, + // Create Coherence Mask + { + source: { + node_id: CANVAS_COHERENCE_MASK_EDGE, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'mask', + }, + }, + { + source: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'denoise_mask', + }, + destination: { + node_id: CANVAS_COHERENCE_DENOISE_LATENTS, + field: 'denoise_mask', + }, + }, // Iterate { source: { @@ -410,7 +442,7 @@ export const buildCanvasSDXLOutpaintGraph = ( }, { source: { - node_id: SDXL_MODEL_LOADER, + node_id: modelLoaderNodeId, field: 'unet', }, destination: { @@ -473,7 +505,6 @@ export const buildCanvasSDXLOutpaintGraph = ( }; // Add Infill Nodes - if (infillMethod === 'patchmatch') { graph.nodes[INPAINT_INFILL] = { type: 'infill_patchmatch', @@ -500,7 +531,7 @@ export const buildCanvasSDXLOutpaintGraph = ( } // Handle Scale Before Processing - if (['auto', 'manual'].includes(boundingBoxScaleMethod)) { + if (isUsingScaledDimensions) { const scaledWidth: number = scaledBoundingBoxDimensions.width; const scaledHeight: number = scaledBoundingBoxDimensions.height; @@ -572,6 +603,16 @@ export const buildCanvasSDXLOutpaintGraph = ( field: 'image', }, }, + { + source: { + node_id: INPAINT_INFILL, + field: 'image', + }, + destination: { + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, + field: 'image', + }, + }, // Take combined mask and resize and then blur { source: { @@ -589,7 +630,7 @@ export const buildCanvasSDXLOutpaintGraph = ( field: 'image', }, destination: { - node_id: MASK_BLUR, + node_id: CANVAS_COHERENCE_MASK_EDGE, field: 'image', }, }, @@ -674,19 +715,26 @@ export const buildCanvasSDXLOutpaintGraph = ( ...(graph.nodes[INPAINT_IMAGE] as ImageToLatentsInvocation), image: canvasInitImage, }; - graph.nodes[MASK_BLUR] = { - ...(graph.nodes[MASK_BLUR] as ImageBlurInvocation), - }; graph.edges.push( // Take combined mask and plug it to blur + { + source: { + node_id: INPAINT_INFILL, + field: 'image', + }, + destination: { + node_id: INPAINT_CREATE_MASK, + field: 'image', + }, + }, { source: { node_id: MASK_COMBINE, field: 'image', }, destination: { - node_id: MASK_BLUR, + node_id: CANVAS_COHERENCE_MASK_EDGE, field: 'image', }, }, @@ -696,7 +744,7 @@ export const buildCanvasSDXLOutpaintGraph = ( field: 'image', }, destination: { - node_id: INPAINT_CREATE_MASK, + node_id: CANVAS_COHERENCE_INPAINT_CREATE_MASK, field: 'image', }, }, @@ -723,7 +771,7 @@ export const buildCanvasSDXLOutpaintGraph = ( }, { source: { - node_id: MASK_BLUR, + node_id: MASK_COMBINE, field: 'image', }, destination: { @@ -734,7 +782,7 @@ export const buildCanvasSDXLOutpaintGraph = ( ); } - // Handle seed + // Handle Seed if (shouldRandomizeSeed) { // Random int node to generate the starting seed const randomIntNode: RandomIntInvocation = { diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/constants.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/constants.ts index 9eaeaa9c7e..70bd0c4058 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/constants.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/constants.ts @@ -27,11 +27,15 @@ export const INPAINT_INFILL = 'inpaint_infill'; export const INPAINT_INFILL_RESIZE_DOWN = 'inpaint_infill_resize_down'; export const INPAINT_FINAL_IMAGE = 'inpaint_final_image'; export const INPAINT_CREATE_MASK = 'inpaint_create_mask'; +export const INPAINT_MASK = 'inpaint_mask'; export const CANVAS_COHERENCE_DENOISE_LATENTS = 'canvas_coherence_denoise_latents'; export const CANVAS_COHERENCE_NOISE = 'canvas_coherence_noise'; export const CANVAS_COHERENCE_NOISE_INCREMENT = 'canvas_coherence_noise_increment'; +export const CANVAS_COHERENCE_MASK_EDGE = 'canvas_coherence_mask_edge'; +export const CANVAS_COHERENCE_INPAINT_CREATE_MASK = + 'canvas_coherence_inpaint_create_mask'; export const MASK_FROM_ALPHA = 'tomask'; export const MASK_EDGE = 'mask_edge'; export const MASK_BLUR = 'mask_blur'; diff --git a/invokeai/frontend/web/src/services/api/types.ts b/invokeai/frontend/web/src/services/api/types.ts index 51e2459b7f..bae60ff701 100644 --- a/invokeai/frontend/web/src/services/api/types.ts +++ b/invokeai/frontend/web/src/services/api/types.ts @@ -112,6 +112,7 @@ export type ImageScaleInvocation = s['ImageScaleInvocation']; export type InfillPatchMatchInvocation = s['InfillPatchMatchInvocation']; export type InfillTileInvocation = s['InfillTileInvocation']; export type CreateDenoiseMaskInvocation = s['CreateDenoiseMaskInvocation']; +export type MaskEdgeInvocation = s['MaskEdgeInvocation']; export type RandomIntInvocation = s['RandomIntInvocation']; export type CompelInvocation = s['CompelInvocation']; export type DynamicPromptInvocation = s['DynamicPromptInvocation'];