kwea123 / nerf_pl

NeRF (Neural Radiance Fields) and NeRF in the Wild using pytorch-lightning
https://www.youtube.com/playlist?list=PLDV2CyUo4q-K02pNEyDr7DYpTQuka3mbV
MIT License
2.74k stars 482 forks source link

Can't extract mesh with exract_mesh.ipynb #131

Closed CozmoxJC closed 2 years ago

CozmoxJC commented 2 years ago

I tried to extract the mesh with the ipynb code, and have the same error messages while searching tight bound of the object as #114 mentioned.

But after I changed two lines of the second block into :

embedding_xyz = Embedding(10)
embedding_dir = Embedding(4)

It showed up the following error messages instead:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_19394/55603309.py in <module>
     34 vertices, triangles = mcubes.marching_cubes(sigma, sigma_threshold)
     35 mesh = trimesh.Trimesh(vertices/N, triangles)
---> 36 mesh.show()

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/base.py in show(self, **kwargs)
   2480         """
   2481         scene = self.scene()
-> 2482         return scene.show(**kwargs)
   2483 
   2484     def submesh(self, faces_sequence, **kwargs):

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/scene/scene.py in show(self, viewer, **kwargs)
   1050         elif viewer == 'notebook':
   1051             from ..viewer import scene_to_notebook
-> 1052             return scene_to_notebook(self, **kwargs)
   1053         else:
   1054             raise ValueError('viewer must be "gl", "notebook", or None')

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/viewer/notebook.py in scene_to_notebook(scene, height, **kwargs)
     65 
     66     # convert scene to a full HTML page
---> 67     as_html = scene_to_html(scene=scene)
     68 
     69     # escape the quotes in the HTML

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/viewer/notebook.py in scene_to_html(scene)
     34         resources.get('viewer.template.zip', decode=False),
     35         file_type='zip')['viewer.html.template'].read().decode('utf-8')
---> 36     scene.camera
     37     # get export as bytes
     38     data = scene.export(file_type='glb')

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/scene/scene.py in camera(self)
    642         if not self.has_camera:
    643             # will create a camera with everything in view
--> 644             return self.set_camera()
    645         assert self._camera is not None
    646 

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/scene/scene.py in set_camera(self, angles, distance, center, resolution, fov)
    559             rotation=rotation,
    560             distance=distance,
--> 561             center=center)
    562 
    563         if hasattr(self, '_camera') and self._camera is not None:

~/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/trimesh/scene/cameras.py in look_at(points, fov, rotation, distance, center, pad)
    327     # Transform points to camera frame (just use the rotation part)
    328     rinv = rotation[:3, :3].T
--> 329     points_c = rinv.dot(points.T).T
    330 
    331     if center is None:

ValueError: shapes (3,3) and (0,) not aligned: 3 (dim 1) != 0 (dim 0)

May I ask how do I fix this problem ?

CozmoxJC commented 2 years ago

Hmm... The error messages are gone by now, It works again.

CozmoxJC commented 2 years ago

This time error occurs at the final block(extract colored mesh), while the others seem fine. The error messages are:

/home/mea303/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ../aten/src/ATen/native/TensorShape.cpp:2157.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Predicting occupancy ...
  0%|                                                  | 0/4096 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "extract_color_mesh.py", line 136, in <module>
    out_chunks += [nerf_fine(xyzdir_embedded)]
  File "/home/mea303/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/mea303/Documents/Python/NeRF_project/nerf_pl-dev/models/nerf.py", line 100, in forward
    torch.split(x, [self.in_channels_xyz, self.in_channels_dir], dim=-1)
  File "/home/mea303/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/torch/functional.py", line 156, in split
    return tensor.split(split_size_or_sections, dim)
  File "/home/mea303/anaconda3/envs/nerf_pl/lib/python3.7/site-packages/torch/_tensor.py", line 518, in split
    return super(Tensor, self).split_with_sizes(split_size, dim)
RuntimeError: start (0) + length (63) exceeds dimension size (42).
kwea123 commented 2 years ago

Hi, I corrected the issue #114 and also the corresponding code in extract_color_mesh.py. Can you pull the latest code and try again? I verified that it worked for lego scene.

CozmoxJC commented 2 years ago

Yes, It works now with the latest code. Thanks for your reply and hard work !!!