IOPaint/lama_cleaner/schema.py

96 lines
3.1 KiB
Python
Raw Normal View History

2022-04-15 18:11:51 +02:00
from enum import Enum
2022-12-10 15:06:15 +01:00
from PIL.Image import Image
2022-04-15 18:11:51 +02:00
from pydantic import BaseModel
class HDStrategy(str, Enum):
2022-11-24 02:29:13 +01:00
# Use original image size
2022-09-22 15:50:41 +02:00
ORIGINAL = "Original"
2022-11-24 02:29:13 +01:00
# Resize the longer side of the image to a specific size(hd_strategy_resize_limit),
# then do inpainting on the resized image. Finally, resize the inpainting result to the original size.
# The area outside the mask will not lose quality.
2022-09-22 15:50:41 +02:00
RESIZE = "Resize"
2022-11-24 02:29:13 +01:00
# Crop masking area(with a margin controlled by hd_strategy_crop_margin) from the original image to do inpainting
2022-09-22 15:50:41 +02:00
CROP = "Crop"
2022-04-15 18:11:51 +02:00
2022-06-12 07:14:17 +02:00
class LDMSampler(str, Enum):
2022-09-22 15:50:41 +02:00
ddim = "ddim"
plms = "plms"
2022-06-12 07:14:17 +02:00
2022-09-22 06:38:32 +02:00
class SDSampler(str, Enum):
2022-09-22 15:50:41 +02:00
ddim = "ddim"
pndm = "pndm"
2022-10-15 16:32:25 +02:00
k_lms = "k_lms"
2022-11-15 14:09:51 +01:00
k_euler = 'k_euler'
k_euler_a = 'k_euler_a'
2022-12-04 06:41:48 +01:00
dpm_plus_plus = 'dpm++'
2022-09-22 06:38:32 +02:00
2022-04-15 18:11:51 +02:00
class Config(BaseModel):
2022-12-10 15:06:15 +01:00
class Config:
arbitrary_types_allowed = True
2022-11-24 02:29:13 +01:00
# Configs for ldm model
2022-04-15 18:11:51 +02:00
ldm_steps: int
2022-07-14 10:49:03 +02:00
ldm_sampler: str = LDMSampler.plms
2022-11-24 02:29:13 +01:00
# Configs for zits model
2022-07-14 10:49:03 +02:00
zits_wireframe: bool = True
2022-11-24 02:29:13 +01:00
# Configs for High Resolution Strategy(different way to preprocess image)
hd_strategy: str # See HDStrategy Enum
2022-04-15 18:11:51 +02:00
hd_strategy_crop_margin: int
2022-11-24 02:29:13 +01:00
# If the longer side of the image is larger than this value, use crop strategy
2022-04-15 18:11:51 +02:00
hd_strategy_crop_trigger_size: int
hd_strategy_resize_limit: int
2022-09-15 16:21:27 +02:00
2022-11-24 02:29:13 +01:00
# Configs for Stable Diffusion 1.5
2022-09-22 15:50:41 +02:00
prompt: str = ""
2022-11-08 14:58:48 +01:00
negative_prompt: str = ""
2022-11-24 02:29:13 +01:00
# Crop image to this size before doing sd inpainting
# The value is always on the original image scale
2022-09-15 16:21:27 +02:00
use_croper: bool = False
croper_x: int = None
croper_y: int = None
croper_height: int = None
croper_width: int = None
2023-01-05 15:07:39 +01:00
# Resize the image before doing sd inpainting, the area outside the mask will not lose quality.
# Used by sd models and paint_by_example model
sd_scale: float = 1.0
2022-11-24 02:29:13 +01:00
# Blur the edge of mask area. The higher the number the smoother blend with the original image
2022-09-22 15:50:41 +02:00
sd_mask_blur: int = 0
2022-11-24 02:29:13 +01:00
# Ignore this value, it's useless for inpainting
2022-09-15 16:21:27 +02:00
sd_strength: float = 0.75
2022-11-24 02:29:13 +01:00
# The number of denoising steps. More denoising steps usually lead to a
# higher quality image at the expense of slower inference.
2022-09-15 16:21:27 +02:00
sd_steps: int = 50
2022-11-24 02:29:13 +01:00
# Higher guidance scale encourages to generate images that are closely linked
# to the text prompt, usually at the expense of lower image quality.
2022-09-15 16:21:27 +02:00
sd_guidance_scale: float = 7.5
2022-09-22 06:38:32 +02:00
sd_sampler: str = SDSampler.ddim
2022-09-15 16:21:27 +02:00
# -1 mean random seed
sd_seed: int = 42
sd_match_histograms: bool = False
2022-10-09 15:32:13 +02:00
2022-11-24 02:29:13 +01:00
# Configs for opencv inpainting
# opencv document https://docs.opencv.org/4.6.0/d7/d8b/group__photo__inpaint.html#gga8002a65f5a3328fbf15df81b842d3c3ca05e763003a805e6c11c673a9f4ba7d07
2022-10-09 15:32:13 +02:00
cv2_flag: str = 'INPAINT_NS'
cv2_radius: int = 4
2022-12-10 15:06:15 +01:00
# Paint by Example
paint_by_example_steps: int = 50
paint_by_example_guidance_scale: float = 7.5
paint_by_example_mask_blur: int = 0
paint_by_example_seed: int = 42
paint_by_example_match_histograms: bool = False
paint_by_example_example_image: Image = None
2023-01-28 14:13:21 +01:00
# InstructPix2Pix
p2p_steps: int = 50
p2p_image_guidance_scale: float = 1.5
p2p_guidance_scale: float = 7.5