Closed monajalal closed 1 year ago
the method extract_mesh
in nerf_runner.py
has no mesh_savepath
arg. Could you please provide the complete code? It seems the current version of code/doc has a bunch of missing items.
Thank you.
@torch.no_grad()
def extract_mesh(self, level=None, voxel_size=0.003, isolevel=0.0, return_sigma=False):
# Query network on dense 3d grid of points
voxel_size *= self.cfg['sc_factor'] # in "network space"
bounds = np.array(self.cfg['bounding_box']).reshape(2,3)
x_min, x_max = bounds[0,0], bounds[1,0]
y_min, y_max = bounds[0,1], bounds[1,1]
z_min, z_max = bounds[0,2], bounds[1,2]
tx = np.arange(x_min+0.5*voxel_size, x_max, voxel_size)
ty = np.arange(y_min+0.5*voxel_size, y_max, voxel_size)
tz = np.arange(z_min+0.5*voxel_size, z_max, voxel_size)
N = len(tx)
query_pts = torch.tensor(np.stack(np.meshgrid(tx, ty, tz, indexing='ij'), -1).astype(np.float32).reshape(-1,3)).float().cuda()
if self.octree_m is not None:
vox_size = self.cfg['octree_raytracing_voxel_size']*self.cfg['sc_factor']
level = int(np.floor(np.log2(2.0/vox_size)))
center_ids = self.octree_m.get_center_ids(query_pts, level)
valid = center_ids>=0
else:
valid = torch.ones(len(query_pts), dtype=bool).cuda()
logging.info(f'query_pts:{query_pts.shape}, valid:{valid.sum()}')
flat = query_pts[valid]
sigma = []
chunk = self.cfg['netchunk']
for i in range(0,flat.shape[0],chunk):
inputs = flat[i:i+chunk]
with torch.no_grad():
outputs,valid_samples = self.run_network_density(inputs=inputs)
sigma.append(outputs)
sigma = torch.cat(sigma, dim=0)
sigma_ = torch.ones((N**3)).float().cuda()
sigma_[valid] = sigma.reshape(-1)
sigma = sigma_.reshape(N,N,N).data.cpu().numpy()
logging.info('Running Marching Cubes')
from skimage import measure
try:
vertices, triangles, normals, values = measure.marching_cubes(sigma, isolevel)
except Exception as e:
logging.info(f"ERROR Marching Cubes {e}")
return None
logging.info(f'done V:{vertices.shape}, F:{triangles.shape}')
# Rescale and translate
voxel_size_ndc = np.array([tx[-1] - tx[0], ty[-1] - ty[0], tz[-1] - tz[0]]) / np.array([[tx.shape[0] - 1, ty.shape[0] - 1, tz.shape[0] - 1]])
offset = np.array([tx[0], ty[0], tz[0]])
vertices[:, :3] = voxel_size_ndc.reshape(1,3) * vertices[:, :3] + offset.reshape(1,3)
# Create mesh
mesh = trimesh.Trimesh(vertices, triangles, process=False)
if return_sigma:
return mesh,sigma,query_pts
return mesh
while:
(base) mona@ard-gpu-01:~/BundleSDF$ rg extract_m
bundlesdf.py
234: mesh = nerf.extract_mesh(isolevel=0,voxel_size=cfg_nerf['mesh_resolution'])
747: mesh,sigma,query_pts = nerf.extract_mesh(voxel_size=self.cfg_nerf['mesh_resolution'],isolevel=0, mesh_savepath='',return_sigma=True)
nerf_runner.py
827: mesh = self.extract_mesh(isolevel=0, voxel_size=self.cfg['mesh_resolution'])
1351: def extract_mesh(self, level=None, voxel_size=0.003, isolevel=0.0, return_sigma=False):
I found this piece of code: https://github.com/dazinovic/neural-rgbd-surface-reconstruction/blob/main/extract_mesh.py#L72
# Create mesh
mesh = trimesh.Trimesh(vertices, triangles, process=False)
if mesh_savepath == '':
mesh_savepath = os.path.join(os.getcwd, f"mesh_vs{voxel_size / self.sc_factor.ply}")
mesh.export(mesh_savepath)
However, I am not fully sure of your intentions and where you want to save them, that's why I have used os.getcwd()
as a filler.
Thanks for reporting the bug. Pushed a fix. Please try again.
I get this error after a very long time of running the command below:
Basically, nothing has been written at all into this folder:
du -h out_dir
shows 2.6G of storage. You know why nothing was written?Number of level 1 directories in
out_dir
:Which is in relation to number of RGB frames in milk: