VikramSingh178 commited on
Commit
5626570
1 Parent(s): fb00a87

chore: Update inpainting pipeline configuration and parameters

Browse files

Former-commit-id: e7d2ea3813700ed8994cf9ada9210b08b1d0d425 [formerly cebfaeaff312b0e8c563bb81b61865d4e8dd186e]
Former-commit-id: ad9d035eaffc7b7de46e960149e59ff2228b2174

Files changed (3) hide show
  1. configs/inpainting.yaml +10 -9
  2. scripts/pipeline.py +13 -8
  3. scripts/utils.py +1 -1
configs/inpainting.yaml CHANGED
@@ -1,13 +1,14 @@
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 : 'product in the kitchen used in cooking 4k'
7
- negative_prompt : 'low resolution , bad resolution'
8
- roi_scale : 0.7
9
- strength : 0.2
10
- guidance_scale : 7.0
11
- num_inference_steps : 800
12
  output_path : '../outputs'
 
13
 
 
1
+ segmentation_model : 'facebook/sam-vit-base'
2
  detection_model : 'yolov8l'
3
  model : 'kandinsky-community/kandinsky-2-2-decoder-inpaint'
4
+ target_width : 2560
5
+ target_height : 1472
6
+ prompt : 'Product on the table 4k ultrarealistic'
7
+ negative_prompt : 'low resolution , bad resolution , Deformation , Weird Artifacts, bad quality,blown up image, high brightness , high saturation '
8
+ roi_scale : 0.6
9
+ strength : 0.5
10
+ guidance_scale : 8
11
+ num_inference_steps : 150
12
  output_path : '../outputs'
13
+
14
 
scripts/pipeline.py CHANGED
@@ -5,7 +5,8 @@ from utils import (accelerator, ImageAugmentation, clear_memory)
5
  import hydra
6
  from omegaconf import DictConfig
7
  from PIL import Image
8
-
 
9
 
10
 
11
 
@@ -19,13 +20,16 @@ class AutoPaintingPipeline:
19
  mask_image (Image): The mask image indicating the areas to be inpainted.
20
  """
21
 
22
- def __init__(self, model_name: str, image: Image, mask_image: Image):
23
  self.model_name = model_name
24
  self.device = accelerator()
25
  self.pipeline = AutoPipelineForInpainting.from_pretrained(self.model_name, torch_dtype=torch.float16)
26
  self.image = load_image(image)
27
  self.mask_image = load_image(mask_image)
 
 
28
  self.pipeline.to(self.device)
 
29
 
30
 
31
 
@@ -39,8 +43,7 @@ class AutoPaintingPipeline:
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 = 1080, width = 1920).images[0]
43
-
44
  return output
45
 
46
 
@@ -52,22 +55,24 @@ def inference(cfg: DictConfig):
52
  Args:
53
  cfg (DictConfig): The configuration file for the inpainting pipeline.
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/example1.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)
61
  mask_image = augmenter.invert_mask(mask_image)
 
62
  prompt = cfg.prompt
63
  negative_prompt = cfg.negative_prompt
64
  num_inference_steps = cfg.num_inference_steps
65
  strength = cfg.strength
66
  guidance_scale = cfg.guidance_scale
67
- pipeline = AutoPaintingPipeline(model_name=model_name, image=extended_image, mask_image=mask_image)
68
  output = pipeline.run_inference(prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, strength=strength, guidance_scale=guidance_scale)
69
  output.save(f'{cfg.output_path}/output.jpg')
70
- return output
 
71
 
72
  if __name__ == "__main__":
73
  inference()
 
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
 
 
20
  mask_image (Image): The mask image indicating the areas to be inpainted.
21
  """
22
 
23
+ def __init__(self, model_name: str, image: Image, mask_image: Image,target_width: int, target_height: int):
24
  self.model_name = model_name
25
  self.device = accelerator()
26
  self.pipeline = AutoPipelineForInpainting.from_pretrained(self.model_name, torch_dtype=torch.float16)
27
  self.image = load_image(image)
28
  self.mask_image = load_image(mask_image)
29
+ self.target_width = target_width
30
+ self.target_height = target_height
31
  self.pipeline.to(self.device)
32
+
33
 
34
 
35
 
 
43
  clear_memory()
44
  image = load_image(self.image)
45
  mask_image = load_image(self.mask_image)
46
+ 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 = self.target_height ,width = self.target_width).images[0]
 
47
  return output
48
 
49
 
 
55
  Args:
56
  cfg (DictConfig): The configuration file for the inpainting pipeline.
57
  """
58
+ augmenter = ImageAugmentation(target_width=cfg.target_width, target_height=cfg.target_height)
59
  model_name = cfg.model
60
+ image_path = "../sample_data/example3.jpg"
61
  image = Image.open(image_path)
62
  extended_image = augmenter.extend_image(image)
63
  mask_image = augmenter.generate_mask_from_bbox(extended_image, cfg.segmentation_model, cfg.detection_model)
64
  mask_image = augmenter.invert_mask(mask_image)
65
+ #mask_image = cv2.GaussianBlur(np.array(mask_image), (7,7), 0)
66
  prompt = cfg.prompt
67
  negative_prompt = cfg.negative_prompt
68
  num_inference_steps = cfg.num_inference_steps
69
  strength = cfg.strength
70
  guidance_scale = cfg.guidance_scale
71
+ pipeline = AutoPaintingPipeline(model_name=model_name, image = extended_image, mask_image=mask_image, target_height=cfg.target_height, target_width=cfg.target_width)
72
  output = pipeline.run_inference(prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, strength=strength, guidance_scale=guidance_scale)
73
  output.save(f'{cfg.output_path}/output.jpg')
74
+ mask_image.save(f'{cfg.output_path}/mask.jpg')
75
+
76
 
77
  if __name__ == "__main__":
78
  inference()
scripts/utils.py CHANGED
@@ -111,7 +111,7 @@ class ImageAugmentation:
111
  return inverted_mask_pil
112
 
113
  if __name__ == "__main__":
114
- augmenter = ImageAugmentation(target_width=2560, target_height=1440, roi_scale=0.7)
115
  image_path = "../sample_data/example3.jpg"
116
  image = Image.open(image_path)
117
  extended_image = augmenter.extend_image(image)
 
111
  return inverted_mask_pil
112
 
113
  if __name__ == "__main__":
114
+ augmenter = ImageAugmentation(target_width=1024, target_height=1024, roi_scale=0.5)
115
  image_path = "../sample_data/example3.jpg"
116
  image = Image.open(image_path)
117
  extended_image = augmenter.extend_image(image)