mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(nodes): fix trivial typing issues
This commit is contained in:
parent
20f6a597ab
commit
49db6f4fac
@ -4,6 +4,7 @@ invokeai.backend.generator.inpaint descends from .generator
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
from typing import Tuple, Union
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -59,7 +60,7 @@ class Inpaint(Img2Img):
|
|||||||
writeable=False,
|
writeable=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def infill_patchmatch(self, im: Image.Image) -> Image:
|
def infill_patchmatch(self, im: Image.Image) -> Image.Image:
|
||||||
if im.mode != "RGBA":
|
if im.mode != "RGBA":
|
||||||
return im
|
return im
|
||||||
|
|
||||||
@ -75,18 +76,18 @@ class Inpaint(Img2Img):
|
|||||||
return im_patched
|
return im_patched
|
||||||
|
|
||||||
def tile_fill_missing(
|
def tile_fill_missing(
|
||||||
self, im: Image.Image, tile_size: int = 16, seed: int = None
|
self, im: Image.Image, tile_size: int = 16, seed: Union[int, None] = None
|
||||||
) -> Image:
|
) -> Image.Image:
|
||||||
# Only fill if there's an alpha layer
|
# Only fill if there's an alpha layer
|
||||||
if im.mode != "RGBA":
|
if im.mode != "RGBA":
|
||||||
return im
|
return im
|
||||||
|
|
||||||
a = np.asarray(im, dtype=np.uint8)
|
a = np.asarray(im, dtype=np.uint8)
|
||||||
|
|
||||||
tile_size = (tile_size, tile_size)
|
tile_size_tuple = (tile_size, tile_size)
|
||||||
|
|
||||||
# Get the image as tiles of a specified size
|
# Get the image as tiles of a specified size
|
||||||
tiles = self.get_tile_images(a, *tile_size).copy()
|
tiles = self.get_tile_images(a, *tile_size_tuple).copy()
|
||||||
|
|
||||||
# Get the mask as tiles
|
# Get the mask as tiles
|
||||||
tiles_mask = tiles[:, :, :, :, 3]
|
tiles_mask = tiles[:, :, :, :, 3]
|
||||||
@ -127,7 +128,9 @@ class Inpaint(Img2Img):
|
|||||||
|
|
||||||
return si
|
return si
|
||||||
|
|
||||||
def mask_edge(self, mask: Image, edge_size: int, edge_blur: int) -> Image:
|
def mask_edge(
|
||||||
|
self, mask: Image.Image, edge_size: int, edge_blur: int
|
||||||
|
) -> Image.Image:
|
||||||
npimg = np.asarray(mask, dtype=np.uint8)
|
npimg = np.asarray(mask, dtype=np.uint8)
|
||||||
|
|
||||||
# Detect any partially transparent regions
|
# Detect any partially transparent regions
|
||||||
@ -206,8 +209,8 @@ class Inpaint(Img2Img):
|
|||||||
cfg_scale,
|
cfg_scale,
|
||||||
ddim_eta,
|
ddim_eta,
|
||||||
conditioning,
|
conditioning,
|
||||||
init_image: PIL.Image.Image | torch.FloatTensor,
|
init_image: Image.Image | torch.FloatTensor,
|
||||||
mask_image: PIL.Image.Image | torch.FloatTensor,
|
mask_image: Image.Image | torch.FloatTensor,
|
||||||
strength: float,
|
strength: float,
|
||||||
mask_blur_radius: int = 8,
|
mask_blur_radius: int = 8,
|
||||||
# Seam settings - when 0, doesn't fill seam
|
# Seam settings - when 0, doesn't fill seam
|
||||||
@ -222,7 +225,7 @@ class Inpaint(Img2Img):
|
|||||||
infill_method=None,
|
infill_method=None,
|
||||||
inpaint_width=None,
|
inpaint_width=None,
|
||||||
inpaint_height=None,
|
inpaint_height=None,
|
||||||
inpaint_fill: tuple(int) = (0x7F, 0x7F, 0x7F, 0xFF),
|
inpaint_fill: Tuple[int, int, int, int] = (0x7F, 0x7F, 0x7F, 0xFF),
|
||||||
attention_maps_callback=None,
|
attention_maps_callback=None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
@ -239,7 +242,7 @@ class Inpaint(Img2Img):
|
|||||||
self.inpaint_width = inpaint_width
|
self.inpaint_width = inpaint_width
|
||||||
self.inpaint_height = inpaint_height
|
self.inpaint_height = inpaint_height
|
||||||
|
|
||||||
if isinstance(init_image, PIL.Image.Image):
|
if isinstance(init_image, Image.Image):
|
||||||
self.pil_image = init_image.copy()
|
self.pil_image = init_image.copy()
|
||||||
|
|
||||||
# Do infill
|
# Do infill
|
||||||
@ -250,8 +253,8 @@ class Inpaint(Img2Img):
|
|||||||
self.pil_image.copy(), seed=self.seed, tile_size=tile_size
|
self.pil_image.copy(), seed=self.seed, tile_size=tile_size
|
||||||
)
|
)
|
||||||
elif infill_method == "solid":
|
elif infill_method == "solid":
|
||||||
solid_bg = PIL.Image.new("RGBA", init_image.size, inpaint_fill)
|
solid_bg = Image.new("RGBA", init_image.size, inpaint_fill)
|
||||||
init_filled = PIL.Image.alpha_composite(solid_bg, init_image)
|
init_filled = Image.alpha_composite(solid_bg, init_image)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Non-supported infill type {infill_method}", infill_method
|
f"Non-supported infill type {infill_method}", infill_method
|
||||||
@ -269,7 +272,7 @@ class Inpaint(Img2Img):
|
|||||||
# Create init tensor
|
# Create init tensor
|
||||||
init_image = image_resized_to_grid_as_tensor(init_filled.convert("RGB"))
|
init_image = image_resized_to_grid_as_tensor(init_filled.convert("RGB"))
|
||||||
|
|
||||||
if isinstance(mask_image, PIL.Image.Image):
|
if isinstance(mask_image, Image.Image):
|
||||||
self.pil_mask = mask_image.copy()
|
self.pil_mask = mask_image.copy()
|
||||||
debug_image(
|
debug_image(
|
||||||
mask_image,
|
mask_image,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user