Spaces:
Running
chore: Update .gitignore and add new files for inpainting pipeline
Browse filesFormer-commit-id: fa322039184db67ead3e25e2c05e822babb4ff0a [formerly f17fae1701fed57adad6c5861841805ef068dec4] [formerly fa322039184db67ead3e25e2c05e822babb4ff0a [formerly f17fae1701fed57adad6c5861841805ef068dec4] [formerly fa322039184db67ead3e25e2c05e822babb4ff0a [formerly f17fae1701fed57adad6c5861841805ef068dec4] [formerly fa322039184db67ead3e25e2c05e822babb4ff0a [formerly f17fae1701fed57adad6c5861841805ef068dec4] [formerly fa322039184db67ead3e25e2c05e822babb4ff0a [formerly f17fae1701fed57adad6c5861841805ef068dec4] [formerly 98433cc2ee6b23538fc629e82c96c608a7ace21d [formerly e830430e6009854c8f7ef28751729b821abdb4b8]]]]]]
Former-commit-id: a047c67c8d6a44940d6f793d6040d5c96b4aa289
Former-commit-id: 3cfe4a976188f13811865cbd2e64c6d0cdb1ed1a
Former-commit-id: 9eab0b8ea82ef3d2e99d557946836ade0207c46a
Former-commit-id: 0e538ae698a204118201ebdf8e4cfe4426d55d63
Former-commit-id: 198d817c16140003dfb3b68db061899c71665d0e
Former-commit-id: 4ee6db316b770852149a1f89c26cabc46e019f44
Former-commit-id: 492a941d6c9badacd0bd2dfcb724718cf6bfe63f
- .gitignore +4 -0
- configs/inpainting.yaml +15 -0
- scripts/api_utils.py +8 -0
- scripts/config.py +13 -0
- scripts/pipeline.py +80 -0
- scripts/yolov8l.pt.REMOVED.git-id +1 -0
@@ -6,7 +6,11 @@ variables.tf
|
|
6 |
config.env
|
7 |
/scripts/yolov8s*
|
8 |
/scripts/*jpg
|
|
|
9 |
/scripts/outputs
|
10 |
=======
|
11 |
scripts/wandb
|
12 |
>>>>>>> bc53421 (Refactor .gitignore, config.py, and wandb scripts, and update requirements.txt)
|
|
|
|
|
|
|
|
6 |
config.env
|
7 |
/scripts/yolov8s*
|
8 |
/scripts/*jpg
|
9 |
+
<<<<<<< HEAD
|
10 |
/scripts/outputs
|
11 |
=======
|
12 |
scripts/wandb
|
13 |
>>>>>>> bc53421 (Refactor .gitignore, config.py, and wandb scripts, and update requirements.txt)
|
14 |
+
=======
|
15 |
+
/scripts/outputs
|
16 |
+
>>>>>>> a817fb6 (chore: Update .gitignore and add new files for inpainting pipeline)
|
@@ -1,3 +1,4 @@
|
|
|
|
1 |
segmentation_model : 'facebook/sam-vit-base'
|
2 |
detection_model : 'yolov8s'
|
3 |
model : 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
|
@@ -11,4 +12,18 @@ guidance_scale : 7
|
|
11 |
num_inference_steps : 150
|
12 |
output_path : '../outputs'
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
1 |
+
<<<<<<< HEAD
|
2 |
segmentation_model : 'facebook/sam-vit-base'
|
3 |
detection_model : 'yolov8s'
|
4 |
model : 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
|
|
|
12 |
num_inference_steps : 150
|
13 |
output_path : '../outputs'
|
14 |
|
15 |
+
=======
|
16 |
+
segmentation_model : 'facebook/sam-vit-large'
|
17 |
+
detection_model : 'yolov8l'
|
18 |
+
model : 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
|
19 |
+
target_width : 1920
|
20 |
+
target_height : 1080
|
21 |
+
prompt : 'product is on the kitchen floor , ultrarealistic lighting , commercial, award , winning photography'
|
22 |
+
negative_prompt : 'low resolution , bad resolution'
|
23 |
+
roi_scale : 0.5
|
24 |
+
strength : 0.7
|
25 |
+
guidance_scale : 7.5
|
26 |
+
num_inference_steps : 600
|
27 |
+
output_path : '../outputs'
|
28 |
+
>>>>>>> a817fb6 (chore: Update .gitignore and add new files for inpainting pipeline)
|
29 |
|
@@ -6,11 +6,15 @@ from PIL import Image, ImageOps
|
|
6 |
from config import SEGMENTATION_MODEL_NAME, DETECTION_MODEL_NAME
|
7 |
from diffusers.utils import load_image
|
8 |
import gc
|
|
|
9 |
from s3_manager import S3ManagerService
|
10 |
import io
|
11 |
from io import BytesIO
|
12 |
import base64
|
13 |
import uuid
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
|
@@ -161,7 +165,11 @@ def pil_to_s3_json(image: Image.Image, file_name) -> dict:
|
|
161 |
|
162 |
|
163 |
if __name__ == "__main__":
|
|
|
164 |
augmenter = ImageAugmentation(target_width=1024, target_height=1024, roi_scale=0.5)
|
|
|
|
|
|
|
165 |
image_path = "../sample_data/example3.jpg"
|
166 |
image = Image.open(image_path)
|
167 |
extended_image = augmenter.extend_image(image)
|
|
|
6 |
from config import SEGMENTATION_MODEL_NAME, DETECTION_MODEL_NAME
|
7 |
from diffusers.utils import load_image
|
8 |
import gc
|
9 |
+
<<<<<<< HEAD:scripts/api_utils.py
|
10 |
from s3_manager import S3ManagerService
|
11 |
import io
|
12 |
from io import BytesIO
|
13 |
import base64
|
14 |
import uuid
|
15 |
+
=======
|
16 |
+
|
17 |
+
>>>>>>> a817fb6 (chore: Update .gitignore and add new files for inpainting pipeline):scripts/utils.py
|
18 |
|
19 |
|
20 |
|
|
|
165 |
|
166 |
|
167 |
if __name__ == "__main__":
|
168 |
+
<<<<<<< HEAD:scripts/api_utils.py
|
169 |
augmenter = ImageAugmentation(target_width=1024, target_height=1024, roi_scale=0.5)
|
170 |
+
=======
|
171 |
+
augmenter = ImageAugmentation(target_width=2560, target_height=1440, roi_scale=0.7)
|
172 |
+
>>>>>>> a817fb6 (chore: Update .gitignore and add new files for inpainting pipeline):scripts/utils.py
|
173 |
image_path = "../sample_data/example3.jpg"
|
174 |
image = Image.open(image_path)
|
175 |
extended_image = augmenter.extend_image(image)
|
@@ -1,4 +1,5 @@
|
|
1 |
<<<<<<< HEAD
|
|
|
2 |
MODEL_NAME:str="stabilityai/stable-diffusion-xl-base-1.0"
|
3 |
ADAPTER_NAME:str = "VikramSingh178/sdxl-lora-finetune-product-caption"
|
4 |
ADAPTER_NAME_2:str = "VikramSingh178/Products10k-SDXL-Lora"
|
@@ -13,6 +14,18 @@ ENABLE_COMPILE:bool = True
|
|
13 |
INPAINTING_MODEL_NAME:str = 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
|
14 |
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
|
|
|
1 |
<<<<<<< HEAD
|
2 |
+
<<<<<<< HEAD
|
3 |
MODEL_NAME:str="stabilityai/stable-diffusion-xl-base-1.0"
|
4 |
ADAPTER_NAME:str = "VikramSingh178/sdxl-lora-finetune-product-caption"
|
5 |
ADAPTER_NAME_2:str = "VikramSingh178/Products10k-SDXL-Lora"
|
|
|
14 |
INPAINTING_MODEL_NAME:str = 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
|
15 |
|
16 |
|
17 |
+
=======
|
18 |
+
MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0"
|
19 |
+
ADAPTER_NAME = "VikramSingh178/sdxl-lora-finetune-product-caption"
|
20 |
+
ADAPTER_NAME_2 = "VikramSingh178/Products10k-SDXL-Lora"
|
21 |
+
VAE_NAME= "madebyollin/sdxl-vae-fp16-fix"
|
22 |
+
DATASET_NAME= "hahminlew/kream-product-blip-captions"
|
23 |
+
PROJECT_NAME = "Product Photography"
|
24 |
+
PRODUCTS_10k_DATASET = "VikramSingh178/Products-10k-BLIP-captions"
|
25 |
+
CAPTIONING_MODEL_NAME = "Salesforce/blip-image-captioning-base"
|
26 |
+
SEGMENTATION_MODEL_NAME = "facebook/sam-vit-large"
|
27 |
+
DETECTION_MODEL_NAME = "yolov8l"
|
28 |
+
>>>>>>> a817fb6 (chore: Update .gitignore and add new files for inpainting pipeline)
|
29 |
|
30 |
|
31 |
|
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from diffusers import ControlNetModel,StableDiffusionControlNetInpaintPipeline,AutoPipelineForInpainting
|
2 |
import torch
|
3 |
|
@@ -90,3 +91,82 @@ def fetch_kandinsky_pipeline(controlnet_adapter_model_name, controlnet_base_mode
|
|
90 |
|
91 |
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<<<<<<< HEAD
|
2 |
from diffusers import ControlNetModel,StableDiffusionControlNetInpaintPipeline,AutoPipelineForInpainting
|
3 |
import torch
|
4 |
|
|
|
91 |
|
92 |
|
93 |
|
94 |
+
=======
|
95 |
+
import torch
|
96 |
+
from diffusers import AutoPipelineForInpainting
|
97 |
+
from diffusers.utils import load_image
|
98 |
+
from utils import (accelerator, ImageAugmentation, clear_memory)
|
99 |
+
import hydra
|
100 |
+
from omegaconf import OmegaConf, DictConfig
|
101 |
+
from PIL import Image
|
102 |
+
import lightning.pytorch as pl
|
103 |
+
pl.seed_everything(42)
|
104 |
+
generator = torch.Generator("cuda").manual_seed(92)
|
105 |
+
|
106 |
+
class AutoPaintingPipeline:
|
107 |
+
"""
|
108 |
+
AutoPaintingPipeline class represents a pipeline for auto painting using an inpainting model from diffusers.
|
109 |
+
|
110 |
+
Args:
|
111 |
+
model_name (str): The name of the pretrained inpainting model.
|
112 |
+
image (Image): The input image to be processed.
|
113 |
+
mask_image (Image): The mask image indicating the areas to be inpainted.
|
114 |
+
"""
|
115 |
+
|
116 |
+
def __init__(self, model_name: str, image: Image, mask_image: Image):
|
117 |
+
self.model_name = model_name
|
118 |
+
self.device = accelerator()
|
119 |
+
self.pipeline = AutoPipelineForInpainting.from_pretrained(self.model_name, torch_dtype=torch.float16)
|
120 |
+
self.image = load_image(image)
|
121 |
+
self.mask_image = load_image(mask_image)
|
122 |
+
self.pipeline.to(self.device)
|
123 |
+
self.pipeline.unet = torch.compile(self.pipeline.unet, mode="reduce-overhead", fullgraph=True)
|
124 |
+
|
125 |
+
|
126 |
+
def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float):
|
127 |
+
"""
|
128 |
+
Runs the inference on the input image using the inpainting pipeline.
|
129 |
+
|
130 |
+
Returns:
|
131 |
+
Image: The output image after inpainting.
|
132 |
+
"""
|
133 |
+
|
134 |
+
image = load_image(self.image)
|
135 |
+
mask_image = load_image(self.mask_image)
|
136 |
+
output = self.pipeline(prompt=prompt,negative_prompt=negative_prompt,image=image,mask_image=mask_image,num_inference_steps=num_inference_steps,strength=strength,guidance_scale =guidance_scale,height = 1472, width = 2560).images[0]
|
137 |
+
clear_memory()
|
138 |
+
return output
|
139 |
+
|
140 |
+
|
141 |
+
@hydra.main(version_base=None ,config_path="../configs", config_name="inpainting")
|
142 |
+
def inference(cfg: DictConfig):
|
143 |
+
"""
|
144 |
+
Load the configuration file for the inpainting pipeline.
|
145 |
+
|
146 |
+
Args:
|
147 |
+
cfg (DictConfig): The configuration file for the inpainting pipeline.
|
148 |
+
"""
|
149 |
+
augmenter = ImageAugmentation(target_width=cfg.target_width, target_height=cfg.target_height, roi_scale=cfg.roi_scale)
|
150 |
+
model_name = cfg.model
|
151 |
+
image_path = "../sample_data/example3.jpg"
|
152 |
+
image = Image.open(image_path)
|
153 |
+
extended_image = augmenter.extend_image(image)
|
154 |
+
mask_image = augmenter.generate_mask_from_bbox(extended_image, cfg.segmentation_model, cfg.detection_model)
|
155 |
+
mask_image = augmenter.invert_mask(mask_image)
|
156 |
+
prompt = cfg.prompt
|
157 |
+
negative_prompt = cfg.negative_prompt
|
158 |
+
num_inference_steps = cfg.num_inference_steps
|
159 |
+
strength = cfg.strength
|
160 |
+
guidance_scale = cfg.guidance_scale
|
161 |
+
pipeline = AutoPaintingPipeline(model_name=model_name, image=extended_image, mask_image=mask_image)
|
162 |
+
output = pipeline.run_inference(prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, strength=strength, guidance_scale=guidance_scale)
|
163 |
+
output.save(f'{cfg.output_path}/output.jpg')
|
164 |
+
return output
|
165 |
+
|
166 |
+
if __name__ == "__main__":
|
167 |
+
inference()
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
|
172 |
+
>>>>>>> a817fb6 (chore: Update .gitignore and add new files for inpainting pipeline)
|
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
4b11a02a7599e520f9f14a4703f4991237d6ce50
|