wip: Add initial Inpaint Graph

This commit is contained in:
blessedcoolant 2023-08-12 02:42:13 +12:00
parent f3ae52ff97
commit 69a9dc7b36
3 changed files with 93 additions and 35 deletions

View File

@ -4,8 +4,8 @@ import { MetadataAccumulatorInvocation } from 'services/api/types';
import { import {
IMAGE_TO_IMAGE_GRAPH, IMAGE_TO_IMAGE_GRAPH,
IMAGE_TO_LATENTS, IMAGE_TO_LATENTS,
INPAINT,
INPAINT_GRAPH, INPAINT_GRAPH,
INPAINT_IMAGE,
LATENTS_TO_IMAGE, LATENTS_TO_IMAGE,
MAIN_MODEL_LOADER, MAIN_MODEL_LOADER,
METADATA_ACCUMULATOR, METADATA_ACCUMULATOR,
@ -35,7 +35,11 @@ export const addVAEToGraph = (
}; };
} }
const isOnnxModel = modelLoaderNodeId == ONNX_MODEL_LOADER; const isOnnxModel = modelLoaderNodeId == ONNX_MODEL_LOADER;
if (graph.id === TEXT_TO_IMAGE_GRAPH || graph.id === IMAGE_TO_IMAGE_GRAPH) { if (
graph.id === TEXT_TO_IMAGE_GRAPH ||
graph.id === IMAGE_TO_IMAGE_GRAPH ||
graph.id === INPAINT_GRAPH
) {
graph.edges.push({ graph.edges.push({
source: { source: {
node_id: isAutoVae ? modelLoaderNodeId : VAE_LOADER, node_id: isAutoVae ? modelLoaderNodeId : VAE_LOADER,
@ -68,7 +72,7 @@ export const addVAEToGraph = (
field: isAutoVae && isOnnxModel ? 'vae_decoder' : 'vae', field: isAutoVae && isOnnxModel ? 'vae_decoder' : 'vae',
}, },
destination: { destination: {
node_id: INPAINT, node_id: INPAINT_IMAGE,
field: 'vae', field: 'vae',
}, },
}); });

View File

@ -3,10 +3,10 @@ import { RootState } from 'app/store/store';
import { NonNullableGraph } from 'features/nodes/types/types'; import { NonNullableGraph } from 'features/nodes/types/types';
import { import {
ImageDTO, ImageDTO,
InpaintInvocation,
RandomIntInvocation, RandomIntInvocation,
RangeOfSizeInvocation, RangeOfSizeInvocation,
} from 'services/api/types'; } from 'services/api/types';
import { addControlNetToLinearGraph } from './addControlNetToLinearGraph';
import { addLoRAsToGraph } from './addLoRAsToGraph'; import { addLoRAsToGraph } from './addLoRAsToGraph';
import { addNSFWCheckerToGraph } from './addNSFWCheckerToGraph'; import { addNSFWCheckerToGraph } from './addNSFWCheckerToGraph';
import { addVAEToGraph } from './addVAEToGraph'; import { addVAEToGraph } from './addVAEToGraph';
@ -15,9 +15,12 @@ import {
CLIP_SKIP, CLIP_SKIP,
INPAINT, INPAINT,
INPAINT_GRAPH, INPAINT_GRAPH,
INPAINT_IMAGE,
ITERATE, ITERATE,
LATENTS_TO_IMAGE,
MAIN_MODEL_LOADER, MAIN_MODEL_LOADER,
NEGATIVE_CONDITIONING, NEGATIVE_CONDITIONING,
NOISE,
POSITIVE_CONDITIONING, POSITIVE_CONDITIONING,
RANDOM_INT, RANDOM_INT,
RANGE_OF_SIZE, RANGE_OF_SIZE,
@ -44,6 +47,9 @@ export const buildCanvasInpaintGraph = (
iterations, iterations,
seed, seed,
shouldRandomizeSeed, shouldRandomizeSeed,
vaePrecision,
shouldUseNoiseSettings,
shouldUseCpuNoise,
seamSize, seamSize,
seamBlur, seamBlur,
seamSteps, seamSteps,
@ -68,40 +74,38 @@ export const buildCanvasInpaintGraph = (
shouldAutoSave, shouldAutoSave,
} = state.canvas; } = state.canvas;
const use_cpu = shouldUseNoiseSettings
? shouldUseCpuNoise
: shouldUseCpuNoise;
const graph: NonNullableGraph = { const graph: NonNullableGraph = {
id: INPAINT_GRAPH, id: INPAINT_GRAPH,
nodes: { nodes: {
[INPAINT]: { [INPAINT]: {
is_intermediate: !shouldAutoSave, type: 'denoise_latents',
type: 'inpaint',
id: INPAINT, id: INPAINT,
steps, is_intermediate: true,
steps: steps,
cfg_scale: cfg_scale,
scheduler: scheduler,
denoising_start: 1 - strength,
denoising_end: 1,
mask: canvasMaskImage,
},
[INPAINT_IMAGE]: {
type: 'i2l',
id: INPAINT_IMAGE,
is_intermediate: true,
image: canvasInitImage,
fp32: vaePrecision === 'fp32' ? true : false,
},
[NOISE]: {
type: 'noise',
id: NOISE,
width, width,
height, height,
cfg_scale, use_cpu,
scheduler, is_intermediate: true,
image: {
image_name: canvasInitImage.image_name,
},
strength,
fit: shouldFitToWidthHeight,
mask: {
image_name: canvasMaskImage.image_name,
},
seam_size: seamSize,
seam_blur: seamBlur,
seam_strength: seamStrength,
seam_steps: seamSteps,
tile_size: infillMethod === 'tile' ? tileSize : undefined,
infill_method: infillMethod as InpaintInvocation['infill_method'],
inpaint_width:
boundingBoxScaleMethod !== 'none'
? scaledBoundingBoxDimensions.width
: undefined,
inpaint_height:
boundingBoxScaleMethod !== 'none'
? scaledBoundingBoxDimensions.height
: undefined,
}, },
[POSITIVE_CONDITIONING]: { [POSITIVE_CONDITIONING]: {
type: 'compel', type: 'compel',
@ -121,12 +125,19 @@ export const buildCanvasInpaintGraph = (
is_intermediate: true, is_intermediate: true,
model, model,
}, },
[LATENTS_TO_IMAGE]: {
type: 'l2i',
id: LATENTS_TO_IMAGE,
is_intermediate: true,
fp32: vaePrecision === 'fp32' ? true : false,
},
[CLIP_SKIP]: { [CLIP_SKIP]: {
type: 'clip_skip', type: 'clip_skip',
id: CLIP_SKIP, id: CLIP_SKIP,
is_intermediate: true, is_intermediate: true,
skipped_layers: clipSkip, skipped_layers: clipSkip,
}, },
[RANGE_OF_SIZE]: { [RANGE_OF_SIZE]: {
type: 'range_of_size', type: 'range_of_size',
id: RANGE_OF_SIZE, id: RANGE_OF_SIZE,
@ -203,6 +214,26 @@ export const buildCanvasInpaintGraph = (
field: 'positive_conditioning', field: 'positive_conditioning',
}, },
}, },
{
source: {
node_id: NOISE,
field: 'noise',
},
destination: {
node_id: INPAINT,
field: 'noise',
},
},
{
source: {
node_id: INPAINT_IMAGE,
field: 'latents',
},
destination: {
node_id: INPAINT,
field: 'latents',
},
},
{ {
source: { source: {
node_id: RANGE_OF_SIZE, node_id: RANGE_OF_SIZE,
@ -219,17 +250,25 @@ export const buildCanvasInpaintGraph = (
field: 'item', field: 'item',
}, },
destination: { destination: {
node_id: INPAINT, node_id: NOISE,
field: 'seed', field: 'seed',
}, },
}, },
{
source: {
node_id: INPAINT,
field: 'latents',
},
destination: {
node_id: LATENTS_TO_IMAGE,
field: 'latents',
},
},
], ],
}; };
addLoRAsToGraph(state, graph, INPAINT);
// Add VAE // Add VAE
addVAEToGraph(state, graph); addVAEToGraph(state, graph, MAIN_MODEL_LOADER);
// handle seed // handle seed
if (shouldRandomizeSeed) { if (shouldRandomizeSeed) {
@ -251,6 +290,12 @@ export const buildCanvasInpaintGraph = (
(graph.nodes[RANGE_OF_SIZE] as RangeOfSizeInvocation).start = seed; (graph.nodes[RANGE_OF_SIZE] as RangeOfSizeInvocation).start = seed;
} }
// add LoRA support
addLoRAsToGraph(state, graph, INPAINT, MAIN_MODEL_LOADER);
// add controlnet, mutating `graph`
addControlNetToLinearGraph(state, graph, INPAINT);
// NSFW & watermark - must be last thing added to graph // NSFW & watermark - must be last thing added to graph
if (state.system.shouldUseNSFWChecker) { if (state.system.shouldUseNSFWChecker) {
// must add before watermarker! // must add before watermarker!

View File

@ -18,6 +18,15 @@ export const IMAGE_TO_LATENTS = 'image_to_latents';
export const LATENTS_TO_LATENTS = 'latents_to_latents'; export const LATENTS_TO_LATENTS = 'latents_to_latents';
export const RESIZE = 'resize_image'; export const RESIZE = 'resize_image';
export const INPAINT = 'inpaint'; export const INPAINT = 'inpaint';
export const INPAINT_SEAM_FIX = 'inpaint_seam_fix';
export const INPAINT_IMAGE = 'inpaint_image';
export const INFILL_TILE = 'infill_tile';
export const INPAINT_FINAL_IMAGE = 'inpaint_final_image';
export const MASK_FROM_ALPHA = 'tomask';
export const MASK_EDGE = 'mask_edge';
export const MASK_BLUR = 'mask_blur';
export const COLOR_CORRECT = 'color_correct';
export const PASTE_IMAGE = 'img_paste';
export const CONTROL_NET_COLLECT = 'control_net_collect'; export const CONTROL_NET_COLLECT = 'control_net_collect';
export const DYNAMIC_PROMPT = 'dynamic_prompt'; export const DYNAMIC_PROMPT = 'dynamic_prompt';
export const IMAGE_COLLECTION = 'image_collection'; export const IMAGE_COLLECTION = 'image_collection';