Commit
Β·
8f63d2f
1
Parent(s):
37052d4
do not use dr
Browse files- app.py +24 -24
- models/DiMeR/models/DiMeR.py +2 -2
- models/DiMeR/models/geometry/rep_3d/flexicubes_geometry.py +28 -28
app.py
CHANGED
|
@@ -172,30 +172,30 @@ def save_py3dmesh_with_trimesh_fast(meshes, save_glb_path=TEMP_MESH_ADDRESS, app
|
|
| 172 |
|
| 173 |
@spaces.GPU(duration=120)
|
| 174 |
def text_to_detailed(prompt, seed=None):
|
| 175 |
-
# test nvdiffrast
|
| 176 |
-
subprocess.run(
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
)
|
| 181 |
-
os.environ["TORCH_CUDA_ARCH_LIST"] = "9.0"
|
| 182 |
-
if "CUDA_VISIBLE_DEVICES" in os.environ:
|
| 183 |
-
|
| 184 |
-
os.environ['CUDA_HOME'] = '/usr/local/cuda-12.1'
|
| 185 |
-
os.environ['PATH'] += ':/usr/local/cuda-12.1/bin'
|
| 186 |
-
os.environ['LD_LIBRARY_PATH'] = "/usr/local/cuda-12.1/lib64:" + os.environ.get('LD_LIBRARY_PATH', '')
|
| 187 |
-
subprocess.run(['nvidia-smi']) # Test if CUDA is available
|
| 188 |
-
print(f"torch.cuda.is_available:{torch.cuda.is_available()}")
|
| 189 |
-
print("Device count:", torch.cuda.device_count())
|
| 190 |
-
subprocess.run(
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
)
|
| 195 |
-
import nvdiffrast.torch as dr
|
| 196 |
-
print("import success")
|
| 197 |
-
dr.RasterizeCudaContext(device="cuda:0")
|
| 198 |
-
print("nvdiffrast initialized successfully")
|
| 199 |
|
| 200 |
print(f"torch.cuda.is_available():{torch.cuda.is_available()}")
|
| 201 |
# print(f"Before text_to_detailed: {torch.cuda.memory_allocated() / 1024**3} GB")
|
|
|
|
| 172 |
|
| 173 |
@spaces.GPU(duration=120)
|
| 174 |
def text_to_detailed(prompt, seed=None):
|
| 175 |
+
# # test nvdiffrast
|
| 176 |
+
# subprocess.run(
|
| 177 |
+
# shlex.split(
|
| 178 |
+
# "rm -rf /home/user/.cache/torch_extensions/py310_cu121/nvdiffrast_plugin/lock"
|
| 179 |
+
# )
|
| 180 |
+
# )
|
| 181 |
+
# os.environ["TORCH_CUDA_ARCH_LIST"] = "9.0"
|
| 182 |
+
# if "CUDA_VISIBLE_DEVICES" in os.environ:
|
| 183 |
+
# del os.environ["CUDA_VISIBLE_DEVICES"]
|
| 184 |
+
# os.environ['CUDA_HOME'] = '/usr/local/cuda-12.1'
|
| 185 |
+
# os.environ['PATH'] += ':/usr/local/cuda-12.1/bin'
|
| 186 |
+
# os.environ['LD_LIBRARY_PATH'] = "/usr/local/cuda-12.1/lib64:" + os.environ.get('LD_LIBRARY_PATH', '')
|
| 187 |
+
# subprocess.run(['nvidia-smi']) # Test if CUDA is available
|
| 188 |
+
# print(f"torch.cuda.is_available:{torch.cuda.is_available()}")
|
| 189 |
+
# print("Device count:", torch.cuda.device_count())
|
| 190 |
+
# subprocess.run(
|
| 191 |
+
# shlex.split(
|
| 192 |
+
# "pip install ./extension/nvdiffrast-0.3.1+torch-py3-none-any.whl --force-reinstall --no-deps"
|
| 193 |
+
# )
|
| 194 |
+
# )
|
| 195 |
+
# import nvdiffrast.torch as dr
|
| 196 |
+
# print("import success")
|
| 197 |
+
# dr.RasterizeCudaContext(device="cuda:0")
|
| 198 |
+
# print("nvdiffrast initialized successfully")
|
| 199 |
|
| 200 |
print(f"torch.cuda.is_available():{torch.cuda.is_available()}")
|
| 201 |
# print(f"Before text_to_detailed: {torch.cuda.memory_allocated() / 1024**3} GB")
|
models/DiMeR/models/DiMeR.py
CHANGED
|
@@ -89,12 +89,12 @@ class DiMeR(nn.Module):
|
|
| 89 |
print(1)
|
| 90 |
camera = PerspectiveCamera(fovy=fovy, device=device)
|
| 91 |
print(2)
|
| 92 |
-
renderer = NeuralRender(device, camera_model=camera)
|
| 93 |
print(3)
|
| 94 |
self.geometry = FlexiCubesGeometry(
|
| 95 |
grid_res=self.grid_res,
|
| 96 |
scale=self.grid_scale,
|
| 97 |
-
renderer=
|
| 98 |
render_type='neural_render',
|
| 99 |
device=device,
|
| 100 |
)
|
|
|
|
| 89 |
print(1)
|
| 90 |
camera = PerspectiveCamera(fovy=fovy, device=device)
|
| 91 |
print(2)
|
| 92 |
+
# renderer = NeuralRender(device, camera_model=camera)
|
| 93 |
print(3)
|
| 94 |
self.geometry = FlexiCubesGeometry(
|
| 95 |
grid_res=self.grid_res,
|
| 96 |
scale=self.grid_scale,
|
| 97 |
+
renderer=None,
|
| 98 |
render_type='neural_render',
|
| 99 |
device=device,
|
| 100 |
)
|
models/DiMeR/models/geometry/rep_3d/flexicubes_geometry.py
CHANGED
|
@@ -67,7 +67,7 @@ class FlexiCubesGeometry(Geometry):
|
|
| 67 |
self.renderer = renderer
|
| 68 |
self.render_type = render_type
|
| 69 |
print(3.8)
|
| 70 |
-
self.ctx = dr.RasterizeCudaContext(device=device)
|
| 71 |
print(3.9)
|
| 72 |
|
| 73 |
# self.verts.requires_grad_(True)
|
|
@@ -153,33 +153,33 @@ class FlexiCubesGeometry(Geometry):
|
|
| 153 |
return verts, faces, v_reg_loss, imesh
|
| 154 |
|
| 155 |
|
| 156 |
-
def render_mesh(self, mesh_v_nx3, mesh_f_fx3, mesh, camera_mv_bx4x4, camera_pos, env, planes, kd_fn, materials, resolution=256, hierarchical_mask=False, gt_albedo_map=None, gt_normal_map=None, gt_depth_map=None, use_PBR=True):
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
|
| 162 |
-
|
| 163 |
|
| 164 |
|
| 165 |
-
def render(self, v_deformed_bxnx3=None, sdf_bxn=None, camera_mv_bxnviewx4x4=None, resolution=256):
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
| 67 |
self.renderer = renderer
|
| 68 |
self.render_type = render_type
|
| 69 |
print(3.8)
|
| 70 |
+
# self.ctx = dr.RasterizeCudaContext(device=device)
|
| 71 |
print(3.9)
|
| 72 |
|
| 73 |
# self.verts.requires_grad_(True)
|
|
|
|
| 153 |
return verts, faces, v_reg_loss, imesh
|
| 154 |
|
| 155 |
|
| 156 |
+
# def render_mesh(self, mesh_v_nx3, mesh_f_fx3, mesh, camera_mv_bx4x4, camera_pos, env, planes, kd_fn, materials, resolution=256, hierarchical_mask=False, gt_albedo_map=None, gt_normal_map=None, gt_depth_map=None, use_PBR=True):
|
| 157 |
+
# return_value = dict()
|
| 158 |
+
# buffer_dict = render.render_mesh(self.ctx, mesh, camera_mv_bx4x4, camera_pos, env,
|
| 159 |
+
# planes, kd_fn, materials, [resolution, resolution],
|
| 160 |
+
# spp=1, num_layers=1, msaa=True, background=None, gt_albedo_map=gt_albedo_map, use_PBR=use_PBR)
|
| 161 |
|
| 162 |
+
# return buffer_dict
|
| 163 |
|
| 164 |
|
| 165 |
+
# def render(self, v_deformed_bxnx3=None, sdf_bxn=None, camera_mv_bxnviewx4x4=None, resolution=256):
|
| 166 |
+
# # Here I assume a batch of meshes (can be different mesh and geometry), for the other shapes, the batch is 1
|
| 167 |
+
# v_list = []
|
| 168 |
+
# f_list = []
|
| 169 |
+
# n_batch = v_deformed_bxnx3.shape[0]
|
| 170 |
+
# all_render_output = []
|
| 171 |
+
# for i_batch in range(n_batch):
|
| 172 |
+
# verts_nx3, faces_fx3 = self.get_mesh(v_deformed_bxnx3[i_batch], sdf_bxn[i_batch])
|
| 173 |
+
# v_list.append(verts_nx3)
|
| 174 |
+
# f_list.append(faces_fx3)
|
| 175 |
+
# render_output = self.render_mesh(verts_nx3, faces_fx3, camera_mv_bxnviewx4x4[i_batch], resolution)
|
| 176 |
+
# all_render_output.append(render_output)
|
| 177 |
+
|
| 178 |
+
# # Concatenate all render output
|
| 179 |
+
# return_keys = all_render_output[0].keys()
|
| 180 |
+
# return_value = dict()
|
| 181 |
+
# for k in return_keys:
|
| 182 |
+
# value = [v[k] for v in all_render_output]
|
| 183 |
+
# return_value[k] = value
|
| 184 |
+
# # We can do concatenation outside of the render
|
| 185 |
+
# return return_value
|