Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export_mesh #24

Open
solomon-ma opened this issue Nov 8, 2023 · 5 comments
Open

export_mesh #24

solomon-ma opened this issue Nov 8, 2023 · 5 comments

Comments

@solomon-ma
Copy link

Could you give a sample code to extract mesh?

I want to sample point in a meshgrid, and use these points to generate a mesh with pretrained model

@solomon-ma
Copy link
Author

如果不能提供提取mesh的代码的话,可否帮忙解答一下level在提取mesh的时候应该如何处理?

  1. 还要构造rays来进行ray_marching等操作,来计算radii,cos和level吗?
  2. 直接在marching cube的bounding box空间内sample points,level设置成统一的值,然后直接query_sdf吗?

@solomon-ma
Copy link
Author

image

I set the level = level_vol in the query_density() function.
the fixed level value give the mesh output like the figure above.

Could you tell me how to set the level value in export mesh process?

@yijicheng
Copy link

@solomon-ma Hi! Could you share your visualization code for mesh?

@solomon-ma
Copy link
Author

solomon-ma commented Dec 5, 2023

   xmin, xmax = config.x_range
    ymin, ymax = config.y_range
    zmin, zmax = config.z_range
    x = np.linspace(xmin, xmax, config.grid_size)
    y = np.linspace(ymin, ymax, config.grid_size)
    z = np.linspace(zmin, zmax, config.grid_size)

    origins = torch.FloatTensor(np.stack(np.meshgrid(x, y, z), -1).reshape(-1, 3)).cuda()
    num_rays = origins.shape[0]

    #第二个参数修改level
    rb = model.field.query_density(origins, torch.full_like(origins[..., :1], 2.4))

   alpha = rb['density']
    import trimesh
    alpha = alpha.cpu().detach().numpy()
    alpha = alpha.reshape(config.grid_size,config.grid_size,config.grid_size)
    vertices, triangles = mcubes.marching_cubes(alpha, 5.0)
    mesh = trimesh.Trimesh(vertices/config.grid_size, triangles)
    mesh.export('./test4.ply')

还有就是neural_field/field/trimipRF.py文件中的query_density()函数做了修改

  def query_density(
        self, x: Tensor, level_vol: Tensor, return_feat: bool = False
    ):
        # level = (
        #     level_vol if level_vol is None else level_vol + self.log2_plane_size
        # )

        level = level_vol

@bobfacer
Copy link

您好!我试用了一下您的这个脚本,出现了如下的问题:

发生异常: RuntimeError
Cuda error: 9[cudaLaunchKernel(func_tbl[func_idx], gridSize, blockSize, args, 0, stream);]
  In call to configurable 'main' (<function main at 0x7fc64cabeee0>)
  File "/data/niuzy/Python/Tri-MipRF/extract_mesh.py", line 56, in main
    trainer.extract_mesh()
  File "/data/niuzy/Python/Tri-MipRF/trainer/trainer.py", line 281, in extract_mesh
    rb = self.model.field.query_density(origins, torch.full_like(origins[..., :1], 2).cuda())
  File "/data/niuzy/Python/Tri-MipRF/neural_field/field/trimipRF.py", line 71, in query_density
    enc = self.encoding(
  File "/data/niuzy/Python/Tri-MipRF/neural_field/encoding/tri_mip.py", line 55, in forward
    enc = nvdiffrast.torch.texture(
RuntimeError: Cuda error: 9[cudaLaunchKernel(func_tbl[func_idx], gridSize, blockSize, args, 0, stream);]

During handling of the above exception, another exception occurred:

  File "/data/niuzy/Python/Tri-MipRF/neural_field/encoding/tri_mip.py", line 55, in forward
    enc = nvdiffrast.torch.texture(
  File "/data/niuzy/Python/Tri-MipRF/neural_field/field/trimipRF.py", line 71, in query_density
    enc = self.encoding(
  File "/data/niuzy/Python/Tri-MipRF/trainer/trainer.py", line 281, in extract_mesh
    rb = self.model.field.query_density(origins, torch.full_like(origins[..., :1], 2).cuda())
  File "/data/niuzy/Python/Tri-MipRF/extract_mesh.py", line 56, in main
    trainer.extract_mesh()
  File "/data/niuzy/Python/Tri-MipRF/extract_mesh.py", line 92, in <module>
    main()
RuntimeError: Cuda error: 9[cudaLaunchKernel(func_tbl[func_idx], gridSize, blockSize, args, 0, stream);]
  In call to configurable 'main' (<function main at 0x7fc64cabeee0>)

请问需要如何解决?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants