feat: Add Infill Method support

This commit is contained in:
blessedcoolant 2023-08-12 05:32:11 +12:00
parent 58a48bf197
commit d7d6298ec0
3 changed files with 40 additions and 2 deletions

View File

@ -3,6 +3,8 @@ import { RootState } from 'app/store/store';
import { NonNullableGraph } from 'features/nodes/types/types'; import { NonNullableGraph } from 'features/nodes/types/types';
import { import {
ImageDTO, ImageDTO,
InfillPatchmatchInvocation,
InfillTileInvocation,
RandomIntInvocation, RandomIntInvocation,
RangeOfSizeInvocation, RangeOfSizeInvocation,
} from 'services/api/types'; } from 'services/api/types';
@ -18,6 +20,7 @@ import {
INPAINT_FINAL_IMAGE, INPAINT_FINAL_IMAGE,
INPAINT_GRAPH, INPAINT_GRAPH,
INPAINT_IMAGE, INPAINT_IMAGE,
INPAINT_INFILL,
ITERATE, ITERATE,
LATENTS_TO_IMAGE, LATENTS_TO_IMAGE,
MAIN_MODEL_LOADER, MAIN_MODEL_LOADER,
@ -60,6 +63,8 @@ export const buildCanvasInpaintGraph = (
clipSkip, clipSkip,
} = state.generation; } = state.generation;
const { generationMode } = state.canvas;
if (!model) { if (!model) {
log.error('No model found in state'); log.error('No model found in state');
throw new Error('No model found in state'); throw new Error('No model found in state');
@ -79,6 +84,23 @@ export const buildCanvasInpaintGraph = (
? shouldUseCpuNoise ? shouldUseCpuNoise
: shouldUseCpuNoise; : shouldUseCpuNoise;
let infillNode: InfillTileInvocation | InfillPatchmatchInvocation = {
type: 'infill_tile',
id: INPAINT_INFILL,
is_intermediate: true,
image: canvasInitImage,
tile_size: tileSize,
};
if (infillMethod === 'patchmatch') {
infillNode = {
type: 'infill_patchmatch',
id: INPAINT_INFILL,
is_intermediate: true,
image: canvasInitImage,
};
}
const graph: NonNullableGraph = { const graph: NonNullableGraph = {
id: INPAINT_GRAPH, id: INPAINT_GRAPH,
nodes: { nodes: {
@ -92,11 +114,11 @@ export const buildCanvasInpaintGraph = (
denoising_start: 1 - strength, denoising_start: 1 - strength,
denoising_end: 1, denoising_end: 1,
}, },
[infillNode.id]: infillNode,
[INPAINT_IMAGE]: { [INPAINT_IMAGE]: {
type: 'i2l', type: 'i2l',
id: INPAINT_IMAGE, id: INPAINT_IMAGE,
is_intermediate: true, is_intermediate: true,
image: canvasInitImage,
fp32: vaePrecision === 'fp32' ? true : false, fp32: vaePrecision === 'fp32' ? true : false,
}, },
[NOISE]: { [NOISE]: {
@ -244,6 +266,16 @@ export const buildCanvasInpaintGraph = (
field: 'noise', field: 'noise',
}, },
}, },
{
source: {
node_id: INPAINT_INFILL,
field: 'image',
},
destination: {
node_id: INPAINT_IMAGE,
field: 'image',
},
},
{ {
source: { source: {
node_id: INPAINT_IMAGE, node_id: INPAINT_IMAGE,

View File

@ -20,7 +20,7 @@ export const RESIZE = 'resize_image';
export const INPAINT = 'inpaint'; export const INPAINT = 'inpaint';
export const INPAINT_SEAM_FIX = 'inpaint_seam_fix'; export const INPAINT_SEAM_FIX = 'inpaint_seam_fix';
export const INPAINT_IMAGE = 'inpaint_image'; export const INPAINT_IMAGE = 'inpaint_image';
export const INFILL_TILE = 'infill_tile'; export const INPAINT_INFILL = 'inpaint_infill';
export const INPAINT_FINAL_IMAGE = 'inpaint_final_image'; export const INPAINT_FINAL_IMAGE = 'inpaint_final_image';
export const MASK_FROM_ALPHA = 'tomask'; export const MASK_FROM_ALPHA = 'tomask';
export const MASK_EDGE = 'mask_edge'; export const MASK_EDGE = 'mask_edge';

View File

@ -172,6 +172,12 @@ export type ESRGANInvocation = TypeReq<
export type DivideInvocation = TypeReq< export type DivideInvocation = TypeReq<
components['schemas']['DivideInvocation'] components['schemas']['DivideInvocation']
>; >;
export type InfillTileInvocation = TypeReq<
components['schemas']['InfillTileInvocation']
>;
export type InfillPatchmatchInvocation = TypeReq<
components['schemas']['InfillPatchMatchInvocation']
>;
export type ImageNSFWBlurInvocation = TypeReq< export type ImageNSFWBlurInvocation = TypeReq<
components['schemas']['ImageNSFWBlurInvocation'] components['schemas']['ImageNSFWBlurInvocation']
>; >;