wbhu / Tri-MipRF

Tri-MipRF: Tri-Mip Representation for Efficient Anti-Aliasing Neural Radiance Fields, ICCV'23 (Oral, Best Paper Finalist)

Home Page:https://wbhu.github.io/projects/Tri-MipRF

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

export_mesh

solomon-ma opened this issue · comments

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

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

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

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?

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

   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

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

发生异常: 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>)

请问需要如何解决?