xinjie.wang commited on
Commit
c103750
·
1 Parent(s): c85a832
Files changed (1) hide show
  1. asset3d_gen/models/delight_model.py +25 -20
asset3d_gen/models/delight_model.py CHANGED
@@ -28,6 +28,7 @@ class DelightingModel(object):
28
  device: str = "cuda",
29
  seed: int = 0,
30
  ) -> None:
 
31
  self.image_guide_scale = image_guide_scale
32
  self.text_guide_scale = text_guide_scale
33
  self.num_infer_step = num_infer_step
@@ -38,28 +39,30 @@ class DelightingModel(object):
38
  self.seed = seed
39
  self.device = device
40
  self.bg_remover = RembgRemover()
41
-
42
- if model_path is None:
43
- suffix = "hunyuan3d-delight-v2-0"
44
- model_path = snapshot_download(
45
- repo_id="tencent/Hunyuan3D-2", allow_patterns=f"{suffix}/*"
 
 
 
 
 
 
 
 
 
 
 
46
  )
47
- model_path = os.path.join(model_path, suffix)
48
-
49
- pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained(
50
- model_path,
51
- torch_dtype=torch.float16,
52
- safety_checker=None,
53
- )
54
- pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(
55
- pipeline.scheduler.config
56
- )
57
- pipeline.set_progress_bar_config(disable=True)
58
 
59
- pipeline.to(self.device, torch.float16)
60
- # pipeline.enable_model_cpu_offload()
61
- # pipeline.enable_xformers_memory_efficient_attention()
62
- self.pipeline = pipeline
63
 
64
  def recenter_image(
65
  self, image: Image.Image, border_ratio: float = 0.2
@@ -110,6 +113,8 @@ class DelightingModel(object):
110
  preprocess: bool = False,
111
  target_wh: tuple[int, int] = None,
112
  ) -> Image.Image:
 
 
113
  if isinstance(image, str):
114
  image = Image.open(image)
115
  elif isinstance(image, np.ndarray):
 
28
  device: str = "cuda",
29
  seed: int = 0,
30
  ) -> None:
31
+ self.model_path = model_path
32
  self.image_guide_scale = image_guide_scale
33
  self.text_guide_scale = text_guide_scale
34
  self.num_infer_step = num_infer_step
 
39
  self.seed = seed
40
  self.device = device
41
  self.bg_remover = RembgRemover()
42
+ self.pipeline = None
43
+
44
+ def _lazy_init_pipeline(self):
45
+ if self.pipeline is None:
46
+ model_path = self.model_path
47
+ if model_path is None:
48
+ suffix = "hunyuan3d-delight-v2-0"
49
+ model_path = snapshot_download(
50
+ repo_id="tencent/Hunyuan3D-2", allow_patterns=f"{suffix}/*"
51
+ )
52
+ model_path = os.path.join(model_path, suffix)
53
+
54
+ pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained(
55
+ model_path,
56
+ torch_dtype=torch.float16,
57
+ safety_checker=None,
58
  )
59
+ pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(
60
+ pipeline.scheduler.config
61
+ )
62
+ pipeline.set_progress_bar_config(disable=True)
 
 
 
 
 
 
 
63
 
64
+ pipeline.to(self.device, torch.float16)
65
+ self.pipeline = pipeline
 
 
66
 
67
  def recenter_image(
68
  self, image: Image.Image, border_ratio: float = 0.2
 
113
  preprocess: bool = False,
114
  target_wh: tuple[int, int] = None,
115
  ) -> Image.Image:
116
+ self._lazy_init_pipeline()
117
+
118
  if isinstance(image, str):
119
  image = Image.open(image)
120
  elif isinstance(image, np.ndarray):