VikramSingh178 commited on
Commit
4fe6ecb
1 Parent(s): 0163ee2

chore: Update inpainting pipeline configuration and parameters

Browse files

Former-commit-id: 8cb2d8ec0b98b85c923b7518f485ac86b934dfb5 [formerly 9f6b6308454760669e28550d2edf3e4c42e65ff7] [formerly 8cb2d8ec0b98b85c923b7518f485ac86b934dfb5 [formerly 9f6b6308454760669e28550d2edf3e4c42e65ff7] [formerly 8cb2d8ec0b98b85c923b7518f485ac86b934dfb5 [formerly 9f6b6308454760669e28550d2edf3e4c42e65ff7] [formerly 8cb2d8ec0b98b85c923b7518f485ac86b934dfb5 [formerly 9f6b6308454760669e28550d2edf3e4c42e65ff7] [formerly 8cb2d8ec0b98b85c923b7518f485ac86b934dfb5 [formerly 9f6b6308454760669e28550d2edf3e4c42e65ff7] [formerly 9ccf8e9ea2ff6e8b5d91537a79af334e8ada1c12 [formerly 8312cab660b7e3f1ac5bf3ecf8f3b9aec6883906]]]]]]
Former-commit-id: 8c59c67439f94d338b8ffd283ef031602285e5e6
Former-commit-id: fcb698fc2f6de6661db9503d7f09f50178cebee6

Former-commit-id: 7e0651408aca6e97917c717d8603d3a376998192
Former-commit-id: ff9f2ab721f17b230df979f91ca1f6af2fcf14c6
Former-commit-id: 6c2917556aa4498e6d9e8a22da28e3a409b5f2cf
Former-commit-id: 66e83994615561cd3351768572b02aefc4a7c898
Former-commit-id: a28cb0e2c326d11c9fb55375ff6a4b71f08eeb76

api/yolov8l.pt.REMOVED.git-id ADDED
@@ -0,0 +1 @@
 
 
1
+ 4b11a02a7599e520f9f14a4703f4991237d6ce50
configs/inpainting.yaml CHANGED
@@ -6,7 +6,11 @@ target_width : 2560
6
  target_height : 1472
7
  prompt : 'Product on the table 4k ultrarealistic'
8
  negative_prompt : 'low resolution , bad resolution , Deformation , Weird Artifacts, bad quality,blown up image, high brightness , high saturation '
 
9
  roi_scale : 0.9
 
 
 
10
  strength : 0.6
11
  guidance_scale : 7
12
  num_inference_steps : 150
 
6
  target_height : 1472
7
  prompt : 'Product on the table 4k ultrarealistic'
8
  negative_prompt : 'low resolution , bad resolution , Deformation , Weird Artifacts, bad quality,blown up image, high brightness , high saturation '
9
+ <<<<<<< HEAD
10
  roi_scale : 0.9
11
+ =======
12
+ roi_scale : 0.5
13
+ >>>>>>> bb1cf42 (chore: Update inpainting pipeline configuration and parameters)
14
  strength : 0.6
15
  guidance_scale : 7
16
  num_inference_steps : 150
scripts/inpainting_pipeline.py CHANGED
@@ -1,11 +1,15 @@
1
  import torch
2
- from diffusers import AutoPipelineForInpainting
3
  from diffusers.utils import load_image
4
  from api_utils import accelerator, ImageAugmentation
5
  import hydra
6
  from omegaconf import DictConfig
7
  from PIL import Image
 
8
 
 
 
 
9
 
10
  def load_pipeline(model_name: str, device, enable_compile: bool = True):
11
  pipeline = AutoPipelineForInpainting.from_pretrained(model_name, torch_dtype=torch.float16)
@@ -15,6 +19,7 @@ def load_pipeline(model_name: str, device, enable_compile: bool = True):
15
  pipeline.to(device)
16
  return pipeline
17
 
 
18
  class AutoPaintingPipeline:
19
  def __init__(self, pipeline, image: Image, mask_image: Image, target_width: int, target_height: int):
20
  self.pipeline = pipeline
@@ -22,6 +27,7 @@ class AutoPaintingPipeline:
22
  self.mask_image = mask_image
23
  self.target_width = target_width
24
  self.target_height = target_height
 
25
 
26
  def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float,num_images):
27
  output = self.pipeline(
@@ -37,6 +43,25 @@ class AutoPaintingPipeline:
37
  width=self.target_width
38
 
39
  ).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  return output
41
 
42
  @hydra.main(version_base=None, config_path="../configs", config_name="inpainting")
@@ -51,6 +76,7 @@ def inference(cfg: DictConfig):
51
  extended_image = augmenter.extend_image(image)
52
  mask_image = augmenter.generate_mask_from_bbox(extended_image, cfg.segmentation_model, cfg.detection_model)
53
  mask_image = augmenter.invert_mask(mask_image)
 
54
 
55
  # Create AutoPaintingPipeline instance with cached pipeline
56
  painting_pipeline = AutoPaintingPipeline(
@@ -71,6 +97,15 @@ def inference(cfg: DictConfig):
71
  )
72
 
73
  # Save output and mask images
 
 
 
 
 
 
 
 
 
74
  output.save(f'{cfg.output_path}/output.jpg')
75
  mask_image.save(f'{cfg.output_path}/mask.jpg')
76
 
 
1
  import torch
2
+ from diffusers import AutoPipelineForInpainting,DiffusionPipeline
3
  from diffusers.utils import load_image
4
  from api_utils import accelerator, ImageAugmentation
5
  import hydra
6
  from omegaconf import DictConfig
7
  from PIL import Image
8
+ <<<<<<< HEAD
9
 
10
+ =======
11
+ from functools import lru_cache
12
+ >>>>>>> bb1cf42 (chore: Update inpainting pipeline configuration and parameters)
13
 
14
  def load_pipeline(model_name: str, device, enable_compile: bool = True):
15
  pipeline = AutoPipelineForInpainting.from_pretrained(model_name, torch_dtype=torch.float16)
 
19
  pipeline.to(device)
20
  return pipeline
21
 
22
+ @lru_cache(maxsize=1)
23
  class AutoPaintingPipeline:
24
  def __init__(self, pipeline, image: Image, mask_image: Image, target_width: int, target_height: int):
25
  self.pipeline = pipeline
 
27
  self.mask_image = mask_image
28
  self.target_width = target_width
29
  self.target_height = target_height
30
+ <<<<<<< HEAD
31
 
32
  def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float,num_images):
33
  output = self.pipeline(
 
43
  width=self.target_width
44
 
45
  ).images[0]
46
+ =======
47
+ self.pipeline.to(self.device)
48
+ self.pipeline.unet = torch.compile(self.pipeline.unet,mode='max-autotune')
49
+
50
+
51
+
52
+
53
+ def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float):
54
+ """
55
+ Runs the inference on the input image using the inpainting pipeline.
56
+
57
+ Returns:
58
+ Image: The output image after inpainting.
59
+ """
60
+
61
+ image = load_image(self.image)
62
+ mask_image = load_image(self.mask_image)
63
+ 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]
64
+ >>>>>>> bb1cf42 (chore: Update inpainting pipeline configuration and parameters)
65
  return output
66
 
67
  @hydra.main(version_base=None, config_path="../configs", config_name="inpainting")
 
76
  extended_image = augmenter.extend_image(image)
77
  mask_image = augmenter.generate_mask_from_bbox(extended_image, cfg.segmentation_model, cfg.detection_model)
78
  mask_image = augmenter.invert_mask(mask_image)
79
+ <<<<<<< HEAD
80
 
81
  # Create AutoPaintingPipeline instance with cached pipeline
82
  painting_pipeline = AutoPaintingPipeline(
 
97
  )
98
 
99
  # Save output and mask images
100
+ =======
101
+ prompt = cfg.prompt
102
+ negative_prompt = cfg.negative_prompt
103
+ num_inference_steps = cfg.num_inference_steps
104
+ strength = cfg.strength
105
+ guidance_scale = cfg.guidance_scale
106
+ pipeline = AutoPaintingPipeline(model_name=model_name, image = extended_image, mask_image=mask_image, target_height=cfg.target_height, target_width=cfg.target_width)
107
+ output = pipeline.run_inference(prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, strength=strength, guidance_scale=guidance_scale)
108
+ >>>>>>> bb1cf42 (chore: Update inpainting pipeline configuration and parameters)
109
  output.save(f'{cfg.output_path}/output.jpg')
110
  mask_image.save(f'{cfg.output_path}/mask.jpg')
111