Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
263eddc
·
1 Parent(s): 411e8a2

Refine color extraction in generate3d function for original mesh

Browse files

- Enhanced the process of extracting per-vertex colors from the original mesh by utilizing tensor operations.
- Implemented a scaling adjustment to ensure color values are within the [0, 1] range.
- Improved overall clarity and performance of the color assignment workflow in the mesh generation process.

Files changed (1) hide show
  1. inference.py +6 -1
inference.py CHANGED
@@ -63,7 +63,12 @@ def generate3d(model, rgb, ccm, device):
63
 
64
  from kiui.mesh_utils import clean_mesh
65
  orig_verts = data_config['verts'].squeeze().cpu().numpy()
66
- orig_colors = ... # get the color for each original vertex, shape [N, 3]
 
 
 
 
 
67
  verts, faces = clean_mesh(
68
  orig_verts.astype(np.float32),
69
  data_config['faces'].squeeze().cpu().numpy().astype(np.int32),
 
63
 
64
  from kiui.mesh_utils import clean_mesh
65
  orig_verts = data_config['verts'].squeeze().cpu().numpy()
66
+ # Extract per-vertex color for the original mesh
67
+ orig_verts_tensor = data_config['verts'].unsqueeze(0) # shape [1, N, 3]
68
+ with torch.no_grad():
69
+ dec_verts = model.decoder(triplane_feature2, orig_verts_tensor)
70
+ orig_colors = model.rgbMlp(dec_verts).squeeze().detach().cpu().numpy()
71
+ orig_colors = (orig_colors * 0.5 + 0.5).clip(0, 1) # scale to [0, 1]
72
  verts, faces = clean_mesh(
73
  orig_verts.astype(np.float32),
74
  data_config['faces'].squeeze().cpu().numpy().astype(np.int32),