VikramSingh178 commited on
Commit
e2ebd5a
β€’
1 Parent(s): fa32203

chore: Update segmentation model to facebook/sam-vit-huge and adjust prompt and negative prompt for inpainting pipeline

Browse files

Former-commit-id: b412e4a5cd45780b141847a85bdff7761bc9acc0 [formerly 43c409b17e48b30006ded8ee7797a4db47748837]
Former-commit-id: 7849cb5077ff5dde7887367b0b2eee19f1e96b91

Files changed (2) hide show
  1. configs/inpainting.yaml +6 -6
  2. scripts/pipeline.py +8 -8
configs/inpainting.yaml CHANGED
@@ -1,13 +1,13 @@
1
- segmentation_model : 'facebook/sam-vit-large'
2
  detection_model : 'yolov8l'
3
  model : 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
4
  target_width : 1920
5
  target_height : 1080
6
- prompt : 'product is on the kitchen floor , ultrarealistic lighting , commercial, award , winning photography'
7
- negative_prompt : 'low resolution , bad resolution'
8
- roi_scale : 0.5
9
- strength : 0.7
10
  guidance_scale : 7.5
11
- num_inference_steps : 600
12
  output_path : '../outputs'
13
 
 
1
+ segmentation_model : 'facebook/sam-vit-huge'
2
  detection_model : 'yolov8l'
3
  model : 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
4
  target_width : 1920
5
  target_height : 1080
6
+ prompt : 'Award Winning Photography of product on a mountain used for camping'
7
+ negative_prompt : 'low resolution , bad resolution, bad quality,bad Artifacts,Weird Artifacts , Poor Lighting'
8
+ roi_scale : 0.6
9
+ strength : 0.2
10
  guidance_scale : 7.5
11
+ num_inference_steps : 800
12
  output_path : '../outputs'
13
 
scripts/pipeline.py CHANGED
@@ -3,11 +3,11 @@ from diffusers import AutoPipelineForInpainting
3
  from diffusers.utils import load_image
4
  from utils import (accelerator, ImageAugmentation, clear_memory)
5
  import hydra
6
- from omegaconf import OmegaConf, DictConfig
7
  from PIL import Image
8
  import lightning.pytorch as pl
9
- pl.seed_everything(42)
10
- generator = torch.Generator("cuda").manual_seed(92)
11
 
12
  class AutoPaintingPipeline:
13
  """
@@ -26,7 +26,7 @@ class AutoPaintingPipeline:
26
  self.image = load_image(image)
27
  self.mask_image = load_image(mask_image)
28
  self.pipeline.to(self.device)
29
- self.pipeline.unet = torch.compile(self.pipeline.unet, mode="reduce-overhead", fullgraph=True)
30
 
31
 
32
  def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float):
@@ -36,11 +36,11 @@ class AutoPaintingPipeline:
36
  Returns:
37
  Image: The output image after inpainting.
38
  """
39
-
40
  image = load_image(self.image)
41
  mask_image = load_image(self.mask_image)
42
- 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]
43
- clear_memory()
44
  return output
45
 
46
 
@@ -54,7 +54,7 @@ def inference(cfg: DictConfig):
54
  """
55
  augmenter = ImageAugmentation(target_width=cfg.target_width, target_height=cfg.target_height, roi_scale=cfg.roi_scale)
56
  model_name = cfg.model
57
- image_path = "../sample_data/example3.jpg"
58
  image = Image.open(image_path)
59
  extended_image = augmenter.extend_image(image)
60
  mask_image = augmenter.generate_mask_from_bbox(extended_image, cfg.segmentation_model, cfg.detection_model)
 
3
  from diffusers.utils import load_image
4
  from utils import (accelerator, ImageAugmentation, clear_memory)
5
  import hydra
6
+ from omegaconf import DictConfig
7
  from PIL import Image
8
  import lightning.pytorch as pl
9
+ pl.seed_everything(1234)
10
+
11
 
12
  class AutoPaintingPipeline:
13
  """
 
26
  self.image = load_image(image)
27
  self.mask_image = load_image(mask_image)
28
  self.pipeline.to(self.device)
29
+
30
 
31
 
32
  def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float):
 
36
  Returns:
37
  Image: The output image after inpainting.
38
  """
39
+ clear_memory()
40
  image = load_image(self.image)
41
  mask_image = load_image(self.mask_image)
42
+ 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]
43
+
44
  return output
45
 
46
 
 
54
  """
55
  augmenter = ImageAugmentation(target_width=cfg.target_width, target_height=cfg.target_height, roi_scale=cfg.roi_scale)
56
  model_name = cfg.model
57
+ image_path = "../sample_data/example5.jpg"
58
  image = Image.open(image_path)
59
  extended_image = augmenter.extend_image(image)
60
  mask_image = augmenter.generate_mask_from_bbox(extended_image, cfg.segmentation_model, cfg.detection_model)