Commit
·
fc24b20
1
Parent(s):
5fe7310
update
Browse files- models/DiMeR/models/DiMeR.py +2 -25
models/DiMeR/models/DiMeR.py
CHANGED
@@ -17,6 +17,7 @@ import torch
|
|
17 |
import torch.nn as nn
|
18 |
import nvdiffrast.torch as dr
|
19 |
from einops import rearrange, repeat
|
|
|
20 |
|
21 |
from .encoder.dino_wrapper import DinoWrapper
|
22 |
from .decoder.transformer import TriplaneTransformer
|
@@ -31,32 +32,8 @@ from PIL import Image
|
|
31 |
import torchvision.utils as vutils
|
32 |
from models.DiMeR.utils import render
|
33 |
from models.DiMeR.utils.render_utils import rotate_x, rotate_y
|
34 |
-
import open3d as o3d
|
35 |
from .geometry.rep_3d import mesh
|
36 |
|
37 |
-
def save_sdf_as_ply(positions, sdf_values, filename, number_samples=100000):
|
38 |
-
# 归一化 SDF 值到 [0, 1] 之间
|
39 |
-
sdf_normalized = (sdf_values - sdf_values.min()) / (sdf_values.max() - sdf_values.min())
|
40 |
-
sdf_normalized = sdf_normalized.squeeze().cpu().numpy()
|
41 |
-
|
42 |
-
if positions.shape[0] > number_samples:
|
43 |
-
indices = np.random.choice(positions.shape[0], number_samples, replace=False)
|
44 |
-
positions = positions[indices]
|
45 |
-
sdf_normalized = sdf_normalized[indices]
|
46 |
-
|
47 |
-
# 创建颜色映射 (从蓝色到红色)
|
48 |
-
colors = np.zeros((sdf_normalized.shape[0], 3), dtype=np.float64)
|
49 |
-
colors[:, 0] = sdf_normalized # Red channel
|
50 |
-
colors[:, 2] = 1.0 - sdf_normalized # Blue channel
|
51 |
-
|
52 |
-
# 创建 Open3D 点云对象
|
53 |
-
point_cloud = o3d.geometry.PointCloud()
|
54 |
-
point_cloud.points = o3d.utility.Vector3dVector(positions.cpu().numpy())
|
55 |
-
point_cloud.colors = o3d.utility.Vector3dVector(colors)
|
56 |
-
|
57 |
-
# 保存为 PLY 文件
|
58 |
-
o3d.io.write_point_cloud(filename, point_cloud)
|
59 |
-
|
60 |
class DiMeR(nn.Module):
|
61 |
"""
|
62 |
Full model of the large reconstruction model.
|
@@ -106,7 +83,7 @@ class DiMeR(nn.Module):
|
|
106 |
samples_per_ray=rendering_samples_per_ray,
|
107 |
use_deformation_weight=use_deformation_weight,
|
108 |
)
|
109 |
-
|
110 |
def init_flexicubes_geometry(self, device, fovy=50.0):
|
111 |
camera = PerspectiveCamera(fovy=fovy, device=device)
|
112 |
renderer = NeuralRender(device, camera_model=camera)
|
|
|
17 |
import torch.nn as nn
|
18 |
import nvdiffrast.torch as dr
|
19 |
from einops import rearrange, repeat
|
20 |
+
import spaces
|
21 |
|
22 |
from .encoder.dino_wrapper import DinoWrapper
|
23 |
from .decoder.transformer import TriplaneTransformer
|
|
|
32 |
import torchvision.utils as vutils
|
33 |
from models.DiMeR.utils import render
|
34 |
from models.DiMeR.utils.render_utils import rotate_x, rotate_y
|
|
|
35 |
from .geometry.rep_3d import mesh
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
class DiMeR(nn.Module):
|
38 |
"""
|
39 |
Full model of the large reconstruction model.
|
|
|
83 |
samples_per_ray=rendering_samples_per_ray,
|
84 |
use_deformation_weight=use_deformation_weight,
|
85 |
)
|
86 |
+
@spaces.GPU
|
87 |
def init_flexicubes_geometry(self, device, fovy=50.0):
|
88 |
camera = PerspectiveCamera(fovy=fovy, device=device)
|
89 |
renderer = NeuralRender(device, camera_model=camera)
|