ZeqiangLai commited on
Commit
6f34049
·
1 Parent(s): 1fd9a2d
Files changed (42) hide show
  1. .gitignore +1 -0
  2. hy3dgen/__init__.py +1 -11
  3. hy3dgen/rembg.py +0 -11
  4. hy3dgen/shapegen/__init__.py +0 -10
  5. hy3dgen/shapegen/models/autoencoders/__init__.py +17 -2
  6. hy3dgen/shapegen/models/autoencoders/attention_blocks.py +15 -0
  7. hy3dgen/shapegen/models/autoencoders/attention_processors.py +77 -0
  8. hy3dgen/shapegen/models/autoencoders/model.py +41 -30
  9. hy3dgen/shapegen/models/autoencoders/surface_extractors.py +14 -0
  10. hy3dgen/shapegen/models/autoencoders/volume_decoders.py +359 -0
  11. hy3dgen/shapegen/models/denoisers/__init__.py +14 -0
  12. hy3dgen/shapegen/models/denoisers/hunyuan3ddit.py +0 -10
  13. hy3dgen/shapegen/pipelines.py +8 -16
  14. hy3dgen/shapegen/postprocessors.py +5 -29
  15. hy3dgen/shapegen/preprocessors.py +7 -28
  16. hy3dgen/shapegen/schedulers.py +14 -0
  17. hy3dgen/shapegen/utils.py +21 -4
  18. hy3dgen/texgen/__init__.py +0 -10
  19. hy3dgen/texgen/custom_rasterizer/custom_rasterizer/__init__.py +0 -10
  20. hy3dgen/texgen/custom_rasterizer/custom_rasterizer/io_glb.py +0 -10
  21. hy3dgen/texgen/custom_rasterizer/custom_rasterizer/io_obj.py +0 -10
  22. hy3dgen/texgen/custom_rasterizer/custom_rasterizer/render.py +0 -10
  23. hy3dgen/texgen/differentiable_renderer/__init__.py +1 -11
  24. hy3dgen/texgen/differentiable_renderer/camera_utils.py +0 -10
  25. hy3dgen/texgen/differentiable_renderer/mesh_processor.py +14 -0
  26. hy3dgen/texgen/differentiable_renderer/mesh_render.py +0 -10
  27. hy3dgen/texgen/differentiable_renderer/mesh_utils.py +0 -10
  28. hy3dgen/texgen/differentiable_renderer/setup.py +14 -0
  29. hy3dgen/texgen/hunyuanpaint/__init__.py +1 -11
  30. hy3dgen/texgen/hunyuanpaint/pipeline.py +5 -13
  31. hy3dgen/texgen/hunyuanpaint/unet/__init__.py +1 -11
  32. hy3dgen/texgen/hunyuanpaint/unet/modules.py +0 -11
  33. hy3dgen/texgen/pipelines.py +13 -16
  34. hy3dgen/texgen/utils/__init__.py +1 -11
  35. hy3dgen/texgen/utils/alignImg4Tex_utils.py +0 -11
  36. hy3dgen/texgen/utils/counter_utils.py +0 -10
  37. hy3dgen/texgen/utils/dehighlight_utils.py +0 -10
  38. hy3dgen/texgen/utils/imagesuper_utils.py +0 -10
  39. hy3dgen/texgen/utils/multiview_utils.py +0 -10
  40. hy3dgen/texgen/utils/simplify_mesh_utils.py +0 -10
  41. hy3dgen/texgen/utils/uv_warp_utils.py +0 -10
  42. hy3dgen/text2image.py +0 -11
.gitignore CHANGED
@@ -2,6 +2,7 @@
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
 
5
 
6
  # C extensions
7
  *.so
 
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
5
+ .DS_Store
6
 
7
  # C extensions
8
  *.so
hy3dgen/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -20,4 +10,4 @@
20
  # their software and algorithms, including trained model weights, parameters (including
21
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
- # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
10
  # their software and algorithms, including trained model weights, parameters (including
11
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
hy3dgen/rembg.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -22,7 +12,6 @@
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
24
 
25
-
26
  from PIL import Image
27
  from rembg import remove, new_session
28
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
 
 
15
  from PIL import Image
16
  from rembg import remove, new_session
17
 
hy3dgen/shapegen/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/shapegen/models/autoencoders/__init__.py CHANGED
@@ -1,5 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from .attention_blocks import CrossAttentionDecoder
2
- from .attention_processors import CrossAttentionProcessor
 
3
  from .model import ShapeVAE, VectsetVAE
4
  from .surface_extractors import SurfaceExtractors, MCSurfaceExtractor, DMCSurfaceExtractor, Latent2MeshOutput
5
- from .volume_decoders import VanillaVolumeDecoder
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  from .attention_blocks import CrossAttentionDecoder
16
+ from .attention_processors import FlashVDMCrossAttentionProcessor, CrossAttentionProcessor, \
17
+ FlashVDMTopMCrossAttentionProcessor
18
  from .model import ShapeVAE, VectsetVAE
19
  from .surface_extractors import SurfaceExtractors, MCSurfaceExtractor, DMCSurfaceExtractor, Latent2MeshOutput
20
+ from .volume_decoders import HierarchicalVolumeDecoding, FlashVDMVolumeDecoding, VanillaVolumeDecoder
hy3dgen/shapegen/models/autoencoders/attention_blocks.py CHANGED
@@ -1,3 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  from typing import Optional
3
 
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
+
16
  import os
17
  from typing import Optional
18
 
hy3dgen/shapegen/models/autoencoders/attention_processors.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
 
3
  import torch
@@ -17,3 +31,66 @@ class CrossAttentionProcessor:
17
  out = scaled_dot_product_attention(q, k, v)
18
  return out
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  import os
16
 
17
  import torch
 
31
  out = scaled_dot_product_attention(q, k, v)
32
  return out
33
 
34
+
35
+ class FlashVDMCrossAttentionProcessor:
36
+ def __init__(self, topk=None):
37
+ self.topk = topk
38
+
39
+ def __call__(self, attn, q, k, v):
40
+ if k.shape[-2] == 3072:
41
+ topk = 1024
42
+ elif k.shape[-2] == 512:
43
+ topk = 256
44
+ else:
45
+ topk = k.shape[-2] // 3
46
+
47
+ if self.topk is True:
48
+ q1 = q[:, :, ::100, :]
49
+ sim = q1 @ k.transpose(-1, -2)
50
+ sim = torch.mean(sim, -2)
51
+ topk_ind = torch.topk(sim, dim=-1, k=topk).indices.squeeze(-2).unsqueeze(-1)
52
+ topk_ind = topk_ind.expand(-1, -1, -1, v.shape[-1])
53
+ v0 = torch.gather(v, dim=-2, index=topk_ind)
54
+ k0 = torch.gather(k, dim=-2, index=topk_ind)
55
+ out = scaled_dot_product_attention(q, k0, v0)
56
+ elif self.topk is False:
57
+ out = scaled_dot_product_attention(q, k, v)
58
+ else:
59
+ idx, counts = self.topk
60
+ start = 0
61
+ outs = []
62
+ for grid_coord, count in zip(idx, counts):
63
+ end = start + count
64
+ q_chunk = q[:, :, start:end, :]
65
+ k0, v0 = self.select_topkv(q_chunk, k, v, topk)
66
+ out = scaled_dot_product_attention(q_chunk, k0, v0)
67
+ outs.append(out)
68
+ start += count
69
+ out = torch.cat(outs, dim=-2)
70
+ self.topk = False
71
+ return out
72
+
73
+ def select_topkv(self, q_chunk, k, v, topk):
74
+ q1 = q_chunk[:, :, ::50, :]
75
+ sim = q1 @ k.transpose(-1, -2)
76
+ sim = torch.mean(sim, -2)
77
+ topk_ind = torch.topk(sim, dim=-1, k=topk).indices.squeeze(-2).unsqueeze(-1)
78
+ topk_ind = topk_ind.expand(-1, -1, -1, v.shape[-1])
79
+ v0 = torch.gather(v, dim=-2, index=topk_ind)
80
+ k0 = torch.gather(k, dim=-2, index=topk_ind)
81
+ return k0, v0
82
+
83
+
84
+ class FlashVDMTopMCrossAttentionProcessor(FlashVDMCrossAttentionProcessor):
85
+ def select_topkv(self, q_chunk, k, v, topk):
86
+ q1 = q_chunk[:, :, ::30, :]
87
+ sim = q1 @ k.transpose(-1, -2)
88
+ # sim = sim.to(torch.float32)
89
+ sim = sim.softmax(-1)
90
+ sim = torch.mean(sim, 1)
91
+ activated_token = torch.where(sim > 1e-6)[2]
92
+ index = torch.unique(activated_token, return_counts=True)[0].unsqueeze(0).unsqueeze(0).unsqueeze(-1)
93
+ index = index.expand(-1, v.shape[1], -1, v.shape[-1])
94
+ v0 = torch.gather(v, dim=-2, index=index)
95
+ k0 = torch.gather(k, dim=-2, index=index)
96
+ return k0, v0
hy3dgen/shapegen/models/autoencoders/model.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
 
3
  import torch
@@ -6,8 +20,8 @@ import yaml
6
 
7
  from .attention_blocks import FourierEmbedder, Transformer, CrossAttentionDecoder
8
  from .surface_extractors import MCSurfaceExtractor, SurfaceExtractors
9
- from .volume_decoders import VanillaVolumeDecoder
10
- from ...utils import logger, synchronize_timer
11
 
12
 
13
  class VectsetVAE(nn.Module):
@@ -59,34 +73,12 @@ class VectsetVAE(nn.Module):
59
  subfolder='hunyuan3d-vae-v2-0',
60
  **kwargs,
61
  ):
62
- original_model_path = model_path
63
- # try local path
64
- base_dir = os.environ.get('HY3DGEN_MODELS', '~/.cache/hy3dgen')
65
- model_path = os.path.expanduser(os.path.join(base_dir, model_path, subfolder))
66
- logger.info(f'Try to load model from local path: {model_path}')
67
- if not os.path.exists(model_path):
68
- logger.info('Model path not exists, try to download from huggingface')
69
- try:
70
- import huggingface_hub
71
- # download from huggingface
72
- path = huggingface_hub.snapshot_download(repo_id=original_model_path)
73
- model_path = os.path.join(path, subfolder)
74
- except ImportError:
75
- logger.warning(
76
- "You need to install HuggingFace Hub to load models from the hub."
77
- )
78
- raise RuntimeError(f"Model path {model_path} not found")
79
- except Exception as e:
80
- raise e
81
-
82
- if not os.path.exists(model_path):
83
- raise FileNotFoundError(f"Model path {original_model_path} not found")
84
-
85
- extension = 'ckpt' if not use_safetensors else 'safetensors'
86
- variant = '' if variant is None else f'.{variant}'
87
- ckpt_name = f'model{variant}.{extension}'
88
- config_path = os.path.join(model_path, 'config.yaml')
89
- ckpt_path = os.path.join(model_path, ckpt_name)
90
 
91
  return cls.from_single_file(
92
  ckpt_path,
@@ -117,6 +109,25 @@ class VectsetVAE(nn.Module):
117
  outputs = self.surface_extractor(grid_logits, **kwargs)
118
  return outputs
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  class ShapeVAE(VectsetVAE):
122
  def __init__(
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  import os
16
 
17
  import torch
 
20
 
21
  from .attention_blocks import FourierEmbedder, Transformer, CrossAttentionDecoder
22
  from .surface_extractors import MCSurfaceExtractor, SurfaceExtractors
23
+ from .volume_decoders import VanillaVolumeDecoder, FlashVDMVolumeDecoding, HierarchicalVolumeDecoding
24
+ from ...utils import logger, synchronize_timer, smart_load_model
25
 
26
 
27
  class VectsetVAE(nn.Module):
 
73
  subfolder='hunyuan3d-vae-v2-0',
74
  **kwargs,
75
  ):
76
+ config_path, ckpt_path = smart_load_model(
77
+ model_path,
78
+ subfolder=subfolder,
79
+ use_safetensors=use_safetensors,
80
+ variant=variant
81
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  return cls.from_single_file(
84
  ckpt_path,
 
109
  outputs = self.surface_extractor(grid_logits, **kwargs)
110
  return outputs
111
 
112
+ def enable_flashvdm_decoder(
113
+ self,
114
+ enabled: bool = True,
115
+ adaptive_kv_selection=True,
116
+ topk_mode='mean',
117
+ mc_algo='dmc',
118
+ ):
119
+ if enabled:
120
+ if adaptive_kv_selection:
121
+ self.volume_decoder = FlashVDMVolumeDecoding(topk_mode)
122
+ else:
123
+ self.volume_decoder = HierarchicalVolumeDecoding()
124
+ if mc_algo not in SurfaceExtractors.keys():
125
+ raise ValueError(f'Unsupported mc_algo {mc_algo}, available: {list(SurfaceExtractors.keys())}')
126
+ self.surface_extractor = SurfaceExtractors[mc_algo]()
127
+ else:
128
+ self.volume_decoder = VanillaVolumeDecoder()
129
+ self.surface_extractor = MCSurfaceExtractor()
130
+
131
 
132
  class ShapeVAE(VectsetVAE):
133
  def __init__(
hy3dgen/shapegen/models/autoencoders/surface_extractors.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from typing import Union, Tuple, List
2
 
3
  import numpy as np
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  from typing import Union, Tuple, List
16
 
17
  import numpy as np
hy3dgen/shapegen/models/autoencoders/volume_decoders.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from typing import Union, Tuple, List, Callable
2
 
3
  import numpy as np
@@ -8,9 +22,103 @@ from einops import repeat
8
  from tqdm import tqdm
9
 
10
  from .attention_blocks import CrossAttentionDecoder
 
11
  from ...utils import logger
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def generate_dense_grid_points(
15
  bbox_min: np.ndarray,
16
  bbox_max: np.ndarray,
@@ -74,3 +182,254 @@ class VanillaVolumeDecoder:
74
  return grid_logits
75
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  from typing import Union, Tuple, List, Callable
16
 
17
  import numpy as np
 
22
  from tqdm import tqdm
23
 
24
  from .attention_blocks import CrossAttentionDecoder
25
+ from .attention_processors import FlashVDMCrossAttentionProcessor, FlashVDMTopMCrossAttentionProcessor
26
  from ...utils import logger
27
 
28
 
29
+ def extract_near_surface_volume_fn(input_tensor: torch.Tensor, alpha: float):
30
+ device = input_tensor.device
31
+ D = input_tensor.shape[0]
32
+ signed_val = 0.0
33
+
34
+ # 添加偏移并处理无效值
35
+ val = input_tensor + alpha
36
+ valid_mask = val > -9000 # 假设-9000是无效值
37
+
38
+ # 改进的邻居获取函数(保持维度一致)
39
+ def get_neighbor(t, shift, axis):
40
+ """根据指定轴进行位移并保持维度一致"""
41
+ if shift == 0:
42
+ return t.clone()
43
+
44
+ # 确定填充轴(输入为[D, D, D]对应z,y,x轴)
45
+ pad_dims = [0, 0, 0, 0, 0, 0] # 格式:[x前,x后,y前,y后,z前,z后]
46
+
47
+ # 根据轴类型设置填充
48
+ if axis == 0: # x轴(最后一个维度)
49
+ pad_idx = 0 if shift > 0 else 1
50
+ pad_dims[pad_idx] = abs(shift)
51
+ elif axis == 1: # y轴(中间维度)
52
+ pad_idx = 2 if shift > 0 else 3
53
+ pad_dims[pad_idx] = abs(shift)
54
+ elif axis == 2: # z轴(第一个维度)
55
+ pad_idx = 4 if shift > 0 else 5
56
+ pad_dims[pad_idx] = abs(shift)
57
+
58
+ # 执行填充(添加batch和channel维度适配F.pad)
59
+ padded = F.pad(t.unsqueeze(0).unsqueeze(0), pad_dims[::-1], mode='replicate') # 反转顺序适配F.pad
60
+
61
+ # 构建动态切片索引
62
+ slice_dims = [slice(None)] * 3 # 初始化为全切片
63
+ if axis == 0: # x轴(dim=2)
64
+ if shift > 0:
65
+ slice_dims[0] = slice(shift, None)
66
+ else:
67
+ slice_dims[0] = slice(None, shift)
68
+ elif axis == 1: # y轴(dim=1)
69
+ if shift > 0:
70
+ slice_dims[1] = slice(shift, None)
71
+ else:
72
+ slice_dims[1] = slice(None, shift)
73
+ elif axis == 2: # z轴(dim=0)
74
+ if shift > 0:
75
+ slice_dims[2] = slice(shift, None)
76
+ else:
77
+ slice_dims[2] = slice(None, shift)
78
+
79
+ # 应用切片并恢复维度
80
+ padded = padded.squeeze(0).squeeze(0)
81
+ sliced = padded[slice_dims]
82
+ return sliced
83
+
84
+ # 获取各方向邻居(确保维度一致)
85
+ left = get_neighbor(val, 1, axis=0) # x方向
86
+ right = get_neighbor(val, -1, axis=0)
87
+ back = get_neighbor(val, 1, axis=1) # y方向
88
+ front = get_neighbor(val, -1, axis=1)
89
+ down = get_neighbor(val, 1, axis=2) # z方向
90
+ up = get_neighbor(val, -1, axis=2)
91
+
92
+ # 处理边界无效值(使用where保持维度一致)
93
+ def safe_where(neighbor):
94
+ return torch.where(neighbor > -9000, neighbor, val)
95
+
96
+ left = safe_where(left)
97
+ right = safe_where(right)
98
+ back = safe_where(back)
99
+ front = safe_where(front)
100
+ down = safe_where(down)
101
+ up = safe_where(up)
102
+
103
+ # 计算符号一致性(转换为float32确保精度)
104
+ sign = torch.sign(val.to(torch.float32))
105
+ neighbors_sign = torch.stack([
106
+ torch.sign(left.to(torch.float32)),
107
+ torch.sign(right.to(torch.float32)),
108
+ torch.sign(back.to(torch.float32)),
109
+ torch.sign(front.to(torch.float32)),
110
+ torch.sign(down.to(torch.float32)),
111
+ torch.sign(up.to(torch.float32))
112
+ ], dim=0)
113
+
114
+ # 检查所有符号是否一致
115
+ same_sign = torch.all(neighbors_sign == sign, dim=0)
116
+
117
+ # 生成最终掩码
118
+ mask = (~same_sign).to(torch.int32)
119
+ return mask * valid_mask.to(torch.int32)
120
+
121
+
122
  def generate_dense_grid_points(
123
  bbox_min: np.ndarray,
124
  bbox_max: np.ndarray,
 
182
  return grid_logits
183
 
184
 
185
+ class HierarchicalVolumeDecoding:
186
+ @torch.no_grad()
187
+ def __call__(
188
+ self,
189
+ latents: torch.FloatTensor,
190
+ geo_decoder: Callable,
191
+ bounds: Union[Tuple[float], List[float], float] = 1.01,
192
+ num_chunks: int = 10000,
193
+ mc_level: float = 0.0,
194
+ octree_resolution: int = None,
195
+ min_resolution: int = 63,
196
+ enable_pbar: bool = True,
197
+ **kwargs,
198
+ ):
199
+ device = latents.device
200
+ dtype = latents.dtype
201
+
202
+ resolutions = []
203
+ if octree_resolution < min_resolution:
204
+ resolutions.append(octree_resolution)
205
+ while octree_resolution >= min_resolution:
206
+ resolutions.append(octree_resolution)
207
+ octree_resolution = octree_resolution // 2
208
+ resolutions.reverse()
209
+
210
+ # 1. generate query points
211
+ if isinstance(bounds, float):
212
+ bounds = [-bounds, -bounds, -bounds, bounds, bounds, bounds]
213
+ bbox_min = np.array(bounds[0:3])
214
+ bbox_max = np.array(bounds[3:6])
215
+ bbox_size = bbox_max - bbox_min
216
+
217
+ xyz_samples, grid_size, length = generate_dense_grid_points(
218
+ bbox_min=bbox_min,
219
+ bbox_max=bbox_max,
220
+ octree_resolution=resolutions[0],
221
+ indexing="ij"
222
+ )
223
+
224
+ dilate = nn.Conv3d(1, 1, 3, padding=1, bias=False, device=device, dtype=dtype)
225
+ dilate.weight = torch.nn.Parameter(torch.ones(dilate.weight.shape, dtype=dtype, device=device))
226
+
227
+ grid_size = np.array(grid_size)
228
+ xyz_samples = torch.from_numpy(xyz_samples).to(device, dtype=dtype).contiguous().reshape(-1, 3)
229
+
230
+ # 2. latents to 3d volume
231
+ batch_logits = []
232
+ batch_size = latents.shape[0]
233
+ for start in tqdm(range(0, xyz_samples.shape[0], num_chunks),
234
+ desc=f"Hierarchical Volume Decoding [r{resolutions[0] + 1}]"):
235
+ queries = xyz_samples[start: start + num_chunks, :]
236
+ batch_queries = repeat(queries, "p c -> b p c", b=batch_size)
237
+ logits = geo_decoder(queries=batch_queries, latents=latents)
238
+ batch_logits.append(logits)
239
+
240
+ grid_logits = torch.cat(batch_logits, dim=1).view((batch_size, grid_size[0], grid_size[1], grid_size[2]))
241
+
242
+ for octree_depth_now in resolutions[1:]:
243
+ grid_size = np.array([octree_depth_now + 1] * 3)
244
+ resolution = bbox_size / octree_depth_now
245
+ next_index = torch.zeros(tuple(grid_size), dtype=dtype, device=device)
246
+ next_logits = torch.full(next_index.shape, -10000., dtype=dtype, device=device)
247
+ curr_points = extract_near_surface_volume_fn(grid_logits.squeeze(0), mc_level)
248
+ curr_points += grid_logits.squeeze(0).abs() < 0.95
249
+
250
+ if octree_depth_now == resolutions[-1]:
251
+ expand_num = 0
252
+ else:
253
+ expand_num = 1
254
+ for i in range(expand_num):
255
+ curr_points = dilate(curr_points.unsqueeze(0).to(dtype)).squeeze(0)
256
+ (cidx_x, cidx_y, cidx_z) = torch.where(curr_points > 0)
257
+ next_index[cidx_x * 2, cidx_y * 2, cidx_z * 2] = 1
258
+ for i in range(2 - expand_num):
259
+ next_index = dilate(next_index.unsqueeze(0)).squeeze(0)
260
+ nidx = torch.where(next_index > 0)
261
+
262
+ next_points = torch.stack(nidx, dim=1)
263
+ next_points = (next_points * torch.tensor(resolution, dtype=next_points.dtype, device=device) +
264
+ torch.tensor(bbox_min, dtype=next_points.dtype, device=device))
265
+ batch_logits = []
266
+ for start in tqdm(range(0, next_points.shape[0], num_chunks),
267
+ desc=f"Hierarchical Volume Decoding [r{octree_depth_now + 1}]"):
268
+ queries = next_points[start: start + num_chunks, :]
269
+ batch_queries = repeat(queries, "p c -> b p c", b=batch_size)
270
+ logits = geo_decoder(queries=batch_queries.to(latents.dtype), latents=latents)
271
+ batch_logits.append(logits)
272
+ grid_logits = torch.cat(batch_logits, dim=1)
273
+ next_logits[nidx] = grid_logits[0, ..., 0]
274
+ grid_logits = next_logits.unsqueeze(0)
275
+ grid_logits[grid_logits == -10000.] = float('nan')
276
+
277
+ return grid_logits
278
+
279
+
280
+ class FlashVDMVolumeDecoding:
281
+ def __init__(self, topk_mode='mean'):
282
+ if topk_mode not in ['mean', 'merge']:
283
+ raise ValueError(f'Unsupported topk_mode {topk_mode}, available: {["mean", "merge"]}')
284
+
285
+ if topk_mode == 'mean':
286
+ self.processor = FlashVDMCrossAttentionProcessor()
287
+ else:
288
+ self.processor = FlashVDMTopMCrossAttentionProcessor()
289
+
290
+ @torch.no_grad()
291
+ def __call__(
292
+ self,
293
+ latents: torch.FloatTensor,
294
+ geo_decoder: CrossAttentionDecoder,
295
+ bounds: Union[Tuple[float], List[float], float] = 1.01,
296
+ num_chunks: int = 10000,
297
+ mc_level: float = 0.0,
298
+ octree_resolution: int = None,
299
+ min_resolution: int = 63,
300
+ mini_grid_num: int = 4,
301
+ enable_pbar: bool = True,
302
+ **kwargs,
303
+ ):
304
+ processor = self.processor
305
+ geo_decoder.set_cross_attention_processor(processor)
306
+
307
+ device = latents.device
308
+ dtype = latents.dtype
309
+
310
+ resolutions = []
311
+ if octree_resolution < min_resolution:
312
+ resolutions.append(octree_resolution)
313
+ while octree_resolution >= min_resolution:
314
+ resolutions.append(octree_resolution)
315
+ octree_resolution = octree_resolution // 2
316
+ resolutions.reverse()
317
+ resolutions[0] = round(resolutions[0] / mini_grid_num) * mini_grid_num - 1
318
+ for i, resolution in enumerate(resolutions[1:]):
319
+ resolutions[i + 1] = resolutions[0] * 2 ** (i + 1)
320
+
321
+ logger.info(f"FlashVDMVolumeDecoding Resolution: {resolutions}")
322
+
323
+ # 1. generate query points
324
+ if isinstance(bounds, float):
325
+ bounds = [-bounds, -bounds, -bounds, bounds, bounds, bounds]
326
+ bbox_min = np.array(bounds[0:3])
327
+ bbox_max = np.array(bounds[3:6])
328
+ bbox_size = bbox_max - bbox_min
329
+
330
+ xyz_samples, grid_size, length = generate_dense_grid_points(
331
+ bbox_min=bbox_min,
332
+ bbox_max=bbox_max,
333
+ octree_resolution=resolutions[0],
334
+ indexing="ij"
335
+ )
336
+
337
+ dilate = nn.Conv3d(1, 1, 3, padding=1, bias=False, device=device, dtype=dtype)
338
+ dilate.weight = torch.nn.Parameter(torch.ones(dilate.weight.shape, dtype=dtype, device=device))
339
+
340
+ grid_size = np.array(grid_size)
341
+
342
+ # 2. latents to 3d volume
343
+ xyz_samples = torch.from_numpy(xyz_samples).to(device, dtype=dtype)
344
+ batch_size = latents.shape[0]
345
+ mini_grid_size = xyz_samples.shape[0] // mini_grid_num
346
+ xyz_samples = xyz_samples.view(
347
+ mini_grid_num, mini_grid_size,
348
+ mini_grid_num, mini_grid_size,
349
+ mini_grid_num, mini_grid_size, 3
350
+ ).permute(
351
+ 0, 2, 4, 1, 3, 5, 6
352
+ ).reshape(
353
+ -1, mini_grid_size * mini_grid_size * mini_grid_size, 3
354
+ )
355
+ batch_logits = []
356
+ num_batchs = max(num_chunks // xyz_samples.shape[1], 1)
357
+ for start in tqdm(range(0, xyz_samples.shape[0], num_batchs),
358
+ desc=f"FlashVDM Volume Decoding", disable=not enable_pbar):
359
+ queries = xyz_samples[start: start + num_batchs, :]
360
+ batch = queries.shape[0]
361
+ batch_latents = repeat(latents.squeeze(0), "p c -> b p c", b=batch)
362
+ processor.topk = True
363
+ logits = geo_decoder(queries=queries, latents=batch_latents)
364
+ batch_logits.append(logits)
365
+ grid_logits = torch.cat(batch_logits, dim=0).reshape(
366
+ mini_grid_num, mini_grid_num, mini_grid_num,
367
+ mini_grid_size, mini_grid_size,
368
+ mini_grid_size
369
+ ).permute(0, 3, 1, 4, 2, 5).contiguous().view(
370
+ (batch_size, grid_size[0], grid_size[1], grid_size[2])
371
+ )
372
+
373
+ for octree_depth_now in resolutions[1:]:
374
+ grid_size = np.array([octree_depth_now + 1] * 3)
375
+ resolution = bbox_size / octree_depth_now
376
+ next_index = torch.zeros(tuple(grid_size), dtype=dtype, device=device)
377
+ next_logits = torch.full(next_index.shape, -10000., dtype=dtype, device=device)
378
+ curr_points = extract_near_surface_volume_fn(grid_logits.squeeze(0), mc_level)
379
+ curr_points += grid_logits.squeeze(0).abs() < 0.95
380
+
381
+ if octree_depth_now == resolutions[-1]:
382
+ expand_num = 0
383
+ else:
384
+ expand_num = 1
385
+ for i in range(expand_num):
386
+ curr_points = dilate(curr_points.unsqueeze(0).to(dtype)).squeeze(0)
387
+ (cidx_x, cidx_y, cidx_z) = torch.where(curr_points > 0)
388
+
389
+ next_index[cidx_x * 2, cidx_y * 2, cidx_z * 2] = 1
390
+ for i in range(2 - expand_num):
391
+ next_index = dilate(next_index.unsqueeze(0)).squeeze(0)
392
+ nidx = torch.where(next_index > 0)
393
+
394
+ next_points = torch.stack(nidx, dim=1)
395
+ next_points = (next_points * torch.tensor(resolution, dtype=torch.float32, device=device) +
396
+ torch.tensor(bbox_min, dtype=torch.float32, device=device))
397
+
398
+ query_grid_num = 6
399
+ min_val = next_points.min(axis=0).values
400
+ max_val = next_points.max(axis=0).values
401
+ vol_queries_index = (next_points - min_val) / (max_val - min_val) * (query_grid_num - 0.001)
402
+ index = torch.floor(vol_queries_index).long()
403
+ index = index[..., 0] * (query_grid_num ** 2) + index[..., 1] * query_grid_num + index[..., 2]
404
+ index = index.sort()
405
+ next_points = next_points[index.indices].unsqueeze(0).contiguous()
406
+ unique_values = torch.unique(index.values, return_counts=True)
407
+ grid_logits = torch.zeros((next_points.shape[1]), dtype=latents.dtype, device=latents.device)
408
+ input_grid = [[], []]
409
+ logits_grid_list = []
410
+ start_num = 0
411
+ sum_num = 0
412
+ for grid_index, count in zip(unique_values[0].cpu().tolist(), unique_values[1].cpu().tolist()):
413
+ if sum_num + count < num_chunks or sum_num == 0:
414
+ sum_num += count
415
+ input_grid[0].append(grid_index)
416
+ input_grid[1].append(count)
417
+ else:
418
+ processor.topk = input_grid
419
+ logits_grid = geo_decoder(queries=next_points[:, start_num:start_num + sum_num], latents=latents)
420
+ start_num = start_num + sum_num
421
+ logits_grid_list.append(logits_grid)
422
+ input_grid = [[grid_index], [count]]
423
+ sum_num = count
424
+ if sum_num > 0:
425
+ processor.topk = input_grid
426
+ logits_grid = geo_decoder(queries=next_points[:, start_num:start_num + sum_num], latents=latents)
427
+ logits_grid_list.append(logits_grid)
428
+ logits_grid = torch.cat(logits_grid_list, dim=1)
429
+ grid_logits[index.indices] = logits_grid.squeeze(0).squeeze(-1)
430
+ next_logits[nidx] = grid_logits
431
+ grid_logits = next_logits.unsqueeze(0)
432
+
433
+ grid_logits[grid_logits == -10000.] = float('nan')
434
+
435
+ return grid_logits
hy3dgen/shapegen/models/denoisers/__init__.py CHANGED
@@ -1 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from .hunyuan3ddit import Hunyuan3DDiT
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  from .hunyuan3ddit import Hunyuan3DDiT
hy3dgen/shapegen/models/denoisers/hunyuan3ddit.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/shapegen/pipelines.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -447,8 +437,6 @@ class Hunyuan3DDiTPipeline:
447
 
448
  cond = cat_recursive(cond, un_cond_drop_main, un_cond)
449
  else:
450
- un_cond = self.conditioner.unconditional_embedding(bsz, **additional_cond_inputs)
451
-
452
  def cat_recursive(a, b):
453
  if isinstance(a, torch.Tensor):
454
  return torch.cat([a, b], dim=0).to(self.dtype)
@@ -587,10 +575,14 @@ class Hunyuan3DDiTPipeline:
587
  getattr(self.model, 'guidance_cond_proj_dim', None) is None
588
  dual_guidance = dual_guidance_scale >= 0 and dual_guidance
589
 
590
- image, mask = self.prepare_image(image)
591
- cond = self.encode_cond(image=image,
592
- do_classifier_free_guidance=do_classifier_free_guidance,
593
- dual_guidance=dual_guidance)
 
 
 
 
594
  batch_size = image.shape[0]
595
 
596
  t_dtype = torch.long
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
437
 
438
  cond = cat_recursive(cond, un_cond_drop_main, un_cond)
439
  else:
 
 
440
  def cat_recursive(a, b):
441
  if isinstance(a, torch.Tensor):
442
  return torch.cat([a, b], dim=0).to(self.dtype)
 
575
  getattr(self.model, 'guidance_cond_proj_dim', None) is None
576
  dual_guidance = dual_guidance_scale >= 0 and dual_guidance
577
 
578
+ cond_inputs = self.prepare_image(image)
579
+ image = cond_inputs.pop('image')
580
+ cond = self.encode_cond(
581
+ image=image,
582
+ additional_cond_inputs=cond_inputs,
583
+ do_classifier_free_guidance=do_classifier_free_guidance,
584
+ dual_guidance=False,
585
+ )
586
  batch_size = image.shape[0]
587
 
588
  t_dtype = torch.long
hy3dgen/shapegen/postprocessors.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -70,7 +60,7 @@ def remove_floater(mesh: pymeshlab.MeshSet):
70
 
71
 
72
  def pymeshlab2trimesh(mesh: pymeshlab.MeshSet):
73
- with tempfile.NamedTemporaryFile(suffix='.ply', delete=True) as temp_file:
74
  mesh.save_current_mesh(temp_file.name)
75
  mesh = trimesh.load(temp_file.name)
76
  # 检查加载的对象类型
@@ -84,7 +74,7 @@ def pymeshlab2trimesh(mesh: pymeshlab.MeshSet):
84
 
85
 
86
  def trimesh2pymeshlab(mesh: trimesh.Trimesh):
87
- with tempfile.NamedTemporaryFile(suffix='.ply', delete=True) as temp_file:
88
  if isinstance(mesh, trimesh.scene.Scene):
89
  for idx, obj in enumerate(mesh.geometry.values()):
90
  if idx == 0:
@@ -158,7 +148,7 @@ class DegenerateFaceRemover:
158
  ) -> Union[pymeshlab.MeshSet, trimesh.Trimesh, Latent2MeshOutput]:
159
  ms = import_mesh(mesh)
160
 
161
- with tempfile.NamedTemporaryFile(suffix='.ply', delete=True) as temp_file:
162
  ms.save_current_mesh(temp_file.name)
163
  ms = pymeshlab.MeshSet()
164
  ms.load_new_mesh(temp_file.name)
@@ -167,20 +157,6 @@ class DegenerateFaceRemover:
167
  return mesh
168
 
169
 
170
- def import_pymeshlab_mesh(mesh: Union[pymeshlab.MeshSet, trimesh.Trimesh, Latent2MeshOutput, str]) -> pymeshlab.MeshSet:
171
- if isinstance(mesh, str):
172
- mesh = load_mesh(mesh)
173
- elif isinstance(mesh, Latent2MeshOutput):
174
- mesh = pymeshlab.MeshSet()
175
- mesh_pymeshlab = pymeshlab.Mesh(vertex_matrix=mesh.mesh_v, face_matrix=mesh.mesh_f)
176
- mesh.add_mesh(mesh_pymeshlab, "converted_mesh")
177
-
178
- if isinstance(mesh, (trimesh.Trimesh, trimesh.scene.Scene)):
179
- mesh = trimesh2pymeshlab(mesh)
180
-
181
- return mesh
182
-
183
-
184
  def mesh_normalize(mesh):
185
  """
186
  Normalize mesh vertices to sphere
@@ -212,8 +188,8 @@ class MeshSimplifier:
212
  self,
213
  mesh: Union[trimesh.Trimesh],
214
  ) -> Union[trimesh.Trimesh]:
215
- with tempfile.NamedTemporaryFile(suffix='.obj', delete=True) as temp_input:
216
- with tempfile.NamedTemporaryFile(suffix='.obj', delete=True) as temp_output:
217
  mesh.export(temp_input.name)
218
  os.system(f'{self.executable} {temp_input.name} {temp_output.name}')
219
  ms = trimesh.load(temp_output.name, process=False)
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
60
 
61
 
62
  def pymeshlab2trimesh(mesh: pymeshlab.MeshSet):
63
+ with tempfile.NamedTemporaryFile(suffix='.ply', delete=False) as temp_file:
64
  mesh.save_current_mesh(temp_file.name)
65
  mesh = trimesh.load(temp_file.name)
66
  # 检查加载的对象类型
 
74
 
75
 
76
  def trimesh2pymeshlab(mesh: trimesh.Trimesh):
77
+ with tempfile.NamedTemporaryFile(suffix='.ply', delete=False) as temp_file:
78
  if isinstance(mesh, trimesh.scene.Scene):
79
  for idx, obj in enumerate(mesh.geometry.values()):
80
  if idx == 0:
 
148
  ) -> Union[pymeshlab.MeshSet, trimesh.Trimesh, Latent2MeshOutput]:
149
  ms = import_mesh(mesh)
150
 
151
+ with tempfile.NamedTemporaryFile(suffix='.ply', delete=False) as temp_file:
152
  ms.save_current_mesh(temp_file.name)
153
  ms = pymeshlab.MeshSet()
154
  ms.load_new_mesh(temp_file.name)
 
157
  return mesh
158
 
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  def mesh_normalize(mesh):
161
  """
162
  Normalize mesh vertices to sphere
 
188
  self,
189
  mesh: Union[trimesh.Trimesh],
190
  ) -> Union[trimesh.Trimesh]:
191
+ with tempfile.NamedTemporaryFile(suffix='.obj', delete=False) as temp_input:
192
+ with tempfile.NamedTemporaryFile(suffix='.obj', delete=False) as temp_output:
193
  mesh.export(temp_input.name)
194
  os.system(f'{self.executable} {temp_input.name} {temp_output.name}')
195
  ms = trimesh.load(temp_output.name, process=False)
hy3dgen/shapegen/preprocessors.py CHANGED
@@ -1,12 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
6
- # The below software and/or models in this distribution may have been
7
- # modified by THL A29 Limited ("Tencent Modifications").
8
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
9
-
10
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
11
  # except for the third-party components listed below.
12
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -96,9 +87,7 @@ class ImageProcessorV2:
96
  mask = mask.clip(0, 255).astype(np.uint8)
97
  return result, mask
98
 
99
- def __call__(self, image, border_ratio=0.15, to_tensor=True, **kwargs):
100
- if self.border_ratio is not None:
101
- border_ratio = self.border_ratio
102
  if isinstance(image, str):
103
  image = cv2.imread(image, cv2.IMREAD_UNCHANGED)
104
  image, mask = self.recenter(image, border_ratio=border_ratio)
@@ -115,7 +104,12 @@ class ImageProcessorV2:
115
  if to_tensor:
116
  image = array_to_tensor(image)
117
  mask = array_to_tensor(mask)
 
118
 
 
 
 
 
119
  outputs = {
120
  'image': image,
121
  'mask': mask
@@ -147,22 +141,7 @@ class MVImageProcessorV2(ImageProcessorV2):
147
  view_idxs = []
148
  for idx, (view_tag, image) in enumerate(image_dict.items()):
149
  view_idxs.append(self.view2idx[view_tag])
150
- if isinstance(image, str):
151
- image = cv2.imread(image, cv2.IMREAD_UNCHANGED)
152
- image, mask = self.recenter(image, border_ratio=border_ratio)
153
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
154
- elif isinstance(image, Image.Image):
155
- image = image.convert("RGBA")
156
- image = np.asarray(image)
157
- image, mask = self.recenter(image, border_ratio=border_ratio)
158
-
159
- image = cv2.resize(image, (self.size, self.size), interpolation=cv2.INTER_CUBIC)
160
- mask = cv2.resize(mask, (self.size, self.size), interpolation=cv2.INTER_NEAREST)
161
- mask = mask[..., np.newaxis]
162
-
163
- if to_tensor:
164
- image = array_to_tensor(image)
165
- mask = array_to_tensor(mask)
166
  images.append(image)
167
  masks.append(mask)
168
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
87
  mask = mask.clip(0, 255).astype(np.uint8)
88
  return result, mask
89
 
90
+ def load_image(self, image, border_ratio=0.15, to_tensor=True):
 
 
91
  if isinstance(image, str):
92
  image = cv2.imread(image, cv2.IMREAD_UNCHANGED)
93
  image, mask = self.recenter(image, border_ratio=border_ratio)
 
104
  if to_tensor:
105
  image = array_to_tensor(image)
106
  mask = array_to_tensor(mask)
107
+ return image, mask
108
 
109
+ def __call__(self, image, border_ratio=0.15, to_tensor=True, **kwargs):
110
+ if self.border_ratio is not None:
111
+ border_ratio = self.border_ratio
112
+ image, mask = self.load_image(image, border_ratio=border_ratio, to_tensor=to_tensor)
113
  outputs = {
114
  'image': image,
115
  'mask': mask
 
141
  view_idxs = []
142
  for idx, (view_tag, image) in enumerate(image_dict.items()):
143
  view_idxs.append(self.view2idx[view_tag])
144
+ image, mask = self.load_image(image, border_ratio=border_ratio, to_tensor=to_tensor)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  images.append(image)
146
  masks.append(mask)
147
 
hy3dgen/shapegen/schedulers.py CHANGED
@@ -12,6 +12,20 @@
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  import math
16
  from dataclasses import dataclass
17
  from typing import List, Optional, Tuple, Union
 
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
 
15
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
16
+ # except for the third-party components listed below.
17
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
18
+ # in the repsective licenses of these third-party components.
19
+ # Users must comply with all terms and conditions of original licenses of these third-party
20
+ # components and must ensure that the usage of the third party components adheres to
21
+ # all relevant laws and regulations.
22
+
23
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
24
+ # their software and algorithms, including trained model weights, parameters (including
25
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
26
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
27
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
28
+
29
  import math
30
  from dataclasses import dataclass
31
  from typing import List, Optional, Tuple, Union
hy3dgen/shapegen/utils.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import logging
2
  import os
3
  from functools import wraps
@@ -86,10 +100,13 @@ def smart_load_model(
86
  if not os.path.exists(model_path):
87
  logger.info('Model path not exists, try to download from huggingface')
88
  try:
89
- import huggingface_hub
90
- # download from huggingface
91
- path = huggingface_hub.snapshot_download(repo_id=original_model_path)
92
- model_path = os.path.join(path, subfolder)
 
 
 
93
  except ImportError:
94
  logger.warning(
95
  "You need to install HuggingFace Hub to load models from the hub."
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  import logging
16
  import os
17
  from functools import wraps
 
100
  if not os.path.exists(model_path):
101
  logger.info('Model path not exists, try to download from huggingface')
102
  try:
103
+ from huggingface_hub import snapshot_download
104
+ # 只下载指定子目录
105
+ path = snapshot_download(
106
+ repo_id=original_model_path,
107
+ allow_patterns=[f"{subfolder}/*"], # 关键修改:模式匹配子文件夹
108
+ )
109
+ model_path = os.path.join(path, subfolder) # 保持路径拼接逻辑不变
110
  except ImportError:
111
  logger.warning(
112
  "You need to install HuggingFace Hub to load models from the hub."
hy3dgen/texgen/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/custom_rasterizer/custom_rasterizer/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/custom_rasterizer/custom_rasterizer/io_glb.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/custom_rasterizer/custom_rasterizer/io_obj.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/custom_rasterizer/custom_rasterizer/render.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/differentiable_renderer/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -20,4 +10,4 @@
20
  # their software and algorithms, including trained model weights, parameters (including
21
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
- # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
10
  # their software and algorithms, including trained model weights, parameters (including
11
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
hy3dgen/texgen/differentiable_renderer/camera_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/differentiable_renderer/mesh_processor.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import numpy as np
2
 
3
  def meshVerticeInpaint_smooth(texture, mask, vtx_pos, vtx_uv, pos_idx, uv_idx):
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  import numpy as np
16
 
17
  def meshVerticeInpaint_smooth(texture, mask, vtx_pos, vtx_uv, pos_idx, uv_idx):
hy3dgen/texgen/differentiable_renderer/mesh_render.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/differentiable_renderer/mesh_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/differentiable_renderer/setup.py CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from setuptools import setup, Extension
2
  import pybind11
3
  import sys
 
1
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
+ # except for the third-party components listed below.
3
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of these third-party components.
5
+ # Users must comply with all terms and conditions of original licenses of these third-party
6
+ # components and must ensure that the usage of the third party components adheres to
7
+ # all relevant laws and regulations.
8
+
9
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters (including
11
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
+
15
  from setuptools import setup, Extension
16
  import pybind11
17
  import sys
hy3dgen/texgen/hunyuanpaint/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -20,4 +10,4 @@
20
  # their software and algorithms, including trained model weights, parameters (including
21
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
- # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
10
  # their software and algorithms, including trained model weights, parameters (including
11
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
hy3dgen/texgen/hunyuanpaint/pipeline.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -119,6 +109,8 @@ class HunyuanPaintPipeline(StableDiffusionPipeline):
119
  return_dict=True,
120
  **cached_condition,
121
  ):
 
 
122
  if image is None:
123
  raise ValueError("Inputting embeddings not supported for this pipeline. Please pass an image.")
124
  assert not isinstance(image, torch.Tensor)
@@ -127,7 +119,7 @@ class HunyuanPaintPipeline(StableDiffusionPipeline):
127
 
128
  image_vae = torch.tensor(np.array(image) / 255.0)
129
  image_vae = image_vae.unsqueeze(0).permute(0, 3, 1, 2).unsqueeze(0)
130
- image_vae = image_vae.to(device=self.vae.device, dtype=self.vae.dtype)
131
 
132
  batch_size = image_vae.shape[0]
133
  assert batch_size == 1
@@ -171,13 +163,13 @@ class HunyuanPaintPipeline(StableDiffusionPipeline):
171
  camera_info = cached_condition['camera_info_gen'] # B,N
172
  if isinstance(camera_info, List):
173
  camera_info = torch.tensor(camera_info)
174
- camera_info = camera_info.to(image_vae.device).to(torch.int64)
175
  cached_condition['camera_info_gen'] = camera_info
176
  if 'camera_info_ref' in cached_condition:
177
  camera_info = cached_condition['camera_info_ref'] # B,N
178
  if isinstance(camera_info, List):
179
  camera_info = torch.tensor(camera_info)
180
- camera_info = camera_info.to(image_vae.device).to(torch.int64)
181
  cached_condition['camera_info_ref'] = camera_info
182
 
183
  cached_condition['ref_latents'] = ref_latents
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
109
  return_dict=True,
110
  **cached_condition,
111
  ):
112
+ device = self._execution_device
113
+
114
  if image is None:
115
  raise ValueError("Inputting embeddings not supported for this pipeline. Please pass an image.")
116
  assert not isinstance(image, torch.Tensor)
 
119
 
120
  image_vae = torch.tensor(np.array(image) / 255.0)
121
  image_vae = image_vae.unsqueeze(0).permute(0, 3, 1, 2).unsqueeze(0)
122
+ image_vae = image_vae.to(device=device, dtype=self.vae.dtype)
123
 
124
  batch_size = image_vae.shape[0]
125
  assert batch_size == 1
 
163
  camera_info = cached_condition['camera_info_gen'] # B,N
164
  if isinstance(camera_info, List):
165
  camera_info = torch.tensor(camera_info)
166
+ camera_info = camera_info.to(device).to(torch.int64)
167
  cached_condition['camera_info_gen'] = camera_info
168
  if 'camera_info_ref' in cached_condition:
169
  camera_info = cached_condition['camera_info_ref'] # B,N
170
  if isinstance(camera_info, List):
171
  camera_info = torch.tensor(camera_info)
172
+ camera_info = camera_info.to(device).to(torch.int64)
173
  cached_condition['camera_info_ref'] = camera_info
174
 
175
  cached_condition['ref_latents'] = ref_latents
hy3dgen/texgen/hunyuanpaint/unet/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -20,4 +10,4 @@
20
  # their software and algorithms, including trained model weights, parameters (including
21
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
- # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
10
  # their software and algorithms, including trained model weights, parameters (including
11
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
hy3dgen/texgen/hunyuanpaint/unet/modules.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -22,7 +12,6 @@
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
24
 
25
-
26
  import copy
27
  import json
28
  import os
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
 
 
15
  import copy
16
  import json
17
  import os
hy3dgen/texgen/pipelines.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -28,6 +18,7 @@ import numpy as np
28
  import os
29
  import torch
30
  from PIL import Image
 
31
 
32
  from .differentiable_renderer.mesh_render import MeshRender
33
  from .utils.dehighlight_utils import Light_Shadow_Remover
@@ -71,7 +62,10 @@ class Hunyuan3DPaintPipeline:
71
  try:
72
  import huggingface_hub
73
  # download from huggingface
74
- model_path = huggingface_hub.snapshot_download(repo_id=original_model_path)
 
 
 
75
  delight_model_path = os.path.join(model_path, 'hunyuan3d-delight-v2-0')
76
  multiview_model_path = os.path.join(model_path, 'hunyuan3d-paint-v2-0')
77
  return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
@@ -79,7 +73,6 @@ class Hunyuan3DPaintPipeline:
79
  logger.warning(
80
  "You need to install HuggingFace Hub to load models from the hub."
81
  )
82
- import traceback;traceback.print_exc()
83
  raise RuntimeError(f"Model path {model_path} not found")
84
  else:
85
  return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
@@ -103,6 +96,10 @@ class Hunyuan3DPaintPipeline:
103
  self.models['multiview_model'] = Multiview_Diffusion_Net(self.config)
104
  # self.models['super_model'] = Image_Super_Net(self.config)
105
 
 
 
 
 
106
  def render_normal_multiview(self, camera_elevs, camera_azims, use_abs_coor=True):
107
  normal_maps = []
108
  for elev, azim in zip(camera_elevs, camera_azims):
@@ -147,14 +144,14 @@ class Hunyuan3DPaintPipeline:
147
  texture = torch.tensor(texture_np / 255).float().to(texture.device)
148
 
149
  return texture
150
-
151
  def recenter_image(self, image, border_ratio=0.2):
152
  if image.mode == 'RGB':
153
  return image
154
  elif image.mode == 'L':
155
  image = image.convert('RGB')
156
  return image
157
-
158
  alpha_channel = np.array(image)[:, :, 3]
159
  non_zero_indices = np.argwhere(alpha_channel > 0)
160
  if non_zero_indices.size == 0:
@@ -189,7 +186,7 @@ class Hunyuan3DPaintPipeline:
189
  image_prompt = Image.open(image)
190
  else:
191
  image_prompt = image
192
-
193
  image_prompt = self.recenter_image(image_prompt)
194
 
195
  image_prompt = self.models['delight_model'](image_prompt)
@@ -212,7 +209,7 @@ class Hunyuan3DPaintPipeline:
212
  multiviews = self.models['multiview_model'](image_prompt, normal_maps + position_maps, camera_info)
213
 
214
  for i in range(len(multiviews)):
215
- # multiviews[i] = self.models['super_model'](multiviews[i])
216
  multiviews[i] = multiviews[i].resize(
217
  (self.config.render_size, self.config.render_size))
218
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
18
  import os
19
  import torch
20
  from PIL import Image
21
+ from typing import Union, Optional
22
 
23
  from .differentiable_renderer.mesh_render import MeshRender
24
  from .utils.dehighlight_utils import Light_Shadow_Remover
 
62
  try:
63
  import huggingface_hub
64
  # download from huggingface
65
+ model_path = huggingface_hub.snapshot_download(repo_id=original_model_path,
66
+ allow_patterns=["hunyuan3d-delight-v2-0/*"])
67
+ model_path = huggingface_hub.snapshot_download(repo_id=original_model_path,
68
+ allow_patterns=["hunyuan3d-paint-v2-0/*"])
69
  delight_model_path = os.path.join(model_path, 'hunyuan3d-delight-v2-0')
70
  multiview_model_path = os.path.join(model_path, 'hunyuan3d-paint-v2-0')
71
  return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
 
73
  logger.warning(
74
  "You need to install HuggingFace Hub to load models from the hub."
75
  )
 
76
  raise RuntimeError(f"Model path {model_path} not found")
77
  else:
78
  return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
 
96
  self.models['multiview_model'] = Multiview_Diffusion_Net(self.config)
97
  # self.models['super_model'] = Image_Super_Net(self.config)
98
 
99
+ def enable_model_cpu_offload(self, gpu_id: Optional[int] = None, device: Union[torch.device, str] = "cuda"):
100
+ self.models['delight_model'].pipeline.enable_model_cpu_offload(gpu_id=gpu_id, device=device)
101
+ self.models['multiview_model'].pipeline.enable_model_cpu_offload(gpu_id=gpu_id, device=device)
102
+
103
  def render_normal_multiview(self, camera_elevs, camera_azims, use_abs_coor=True):
104
  normal_maps = []
105
  for elev, azim in zip(camera_elevs, camera_azims):
 
144
  texture = torch.tensor(texture_np / 255).float().to(texture.device)
145
 
146
  return texture
147
+
148
  def recenter_image(self, image, border_ratio=0.2):
149
  if image.mode == 'RGB':
150
  return image
151
  elif image.mode == 'L':
152
  image = image.convert('RGB')
153
  return image
154
+
155
  alpha_channel = np.array(image)[:, :, 3]
156
  non_zero_indices = np.argwhere(alpha_channel > 0)
157
  if non_zero_indices.size == 0:
 
186
  image_prompt = Image.open(image)
187
  else:
188
  image_prompt = image
189
+
190
  image_prompt = self.recenter_image(image_prompt)
191
 
192
  image_prompt = self.models['delight_model'](image_prompt)
 
209
  multiviews = self.models['multiview_model'](image_prompt, normal_maps + position_maps, camera_info)
210
 
211
  for i in range(len(multiviews)):
212
+ # multiviews[i] = self.models['super_model'](multiviews[i])
213
  multiviews[i] = multiviews[i].resize(
214
  (self.config.render_size, self.config.render_size))
215
 
hy3dgen/texgen/utils/__init__.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -20,4 +10,4 @@
20
  # their software and algorithms, including trained model weights, parameters (including
21
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
- # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
10
  # their software and algorithms, including trained model weights, parameters (including
11
  # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
hy3dgen/texgen/utils/alignImg4Tex_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -22,7 +12,6 @@
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
24
 
25
-
26
  import torch
27
  from diffusers import EulerAncestralDiscreteScheduler
28
  from diffusers import StableDiffusionControlNetPipeline, StableDiffusionXLControlNetImg2ImgPipeline, ControlNetModel, \
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
 
 
15
  import torch
16
  from diffusers import EulerAncestralDiscreteScheduler
17
  from diffusers import StableDiffusionControlNetPipeline, StableDiffusionXLControlNetImg2ImgPipeline, ControlNetModel, \
hy3dgen/texgen/utils/counter_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/utils/dehighlight_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/utils/imagesuper_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/utils/multiview_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/utils/simplify_mesh_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/texgen/utils/uv_warp_utils.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
hy3dgen/text2image.py CHANGED
@@ -1,13 +1,3 @@
1
- # Open Source Model Licensed under the Apache License Version 2.0
2
- # and Other Licenses of the Third-Party Components therein:
3
- # The below Model in this distribution may have been modified by THL A29 Limited
4
- # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
-
6
- # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
- # The below software and/or models in this distribution may have been
8
- # modified by THL A29 Limited ("Tencent Modifications").
9
- # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
-
11
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
  # except for the third-party components listed below.
13
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
@@ -22,7 +12,6 @@
22
  # fine-tuning enabling code and other elements of the foregoing made publicly available
23
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
24
 
25
-
26
  import os
27
  import random
28
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
 
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
 
 
15
  import os
16
  import random
17