Gary3410 commited on
Commit
fdfd1d3
1 Parent(s): fdb7fbb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -5,6 +5,14 @@ import numpy
5
  import trimesh
6
 
7
 
 
 
 
 
 
 
 
 
8
 
9
  def model_to_pc(mesh: trimesh.Trimesh, n_sample_points=10000):
10
  f32 = numpy.float32
@@ -99,6 +107,7 @@ for objaid in random_object_uids:
99
  objamodel = objaverse.load_objects([objaid])[objaid]
100
  try:
101
  pc = trimesh_to_pc(trimesh.load(objamodel))
 
102
  pc_list.append(pc.reshape([1, -1, pc.shape[-1]]))
103
  except:
104
  continue
 
5
  import trimesh
6
 
7
 
8
+ def random_sampling(points, num_samples):
9
+ # 如果点云数量小于采样数量,允许重复选择点
10
+ if len(points) < num_samples:
11
+ indices = numpy.random.choice(len(points), num_samples, replace=True)
12
+ else:
13
+ indices = numpy.random.choice(len(points), num_samples, replace=False)
14
+ sampled_points = points[indices]
15
+ return sampled_points
16
 
17
  def model_to_pc(mesh: trimesh.Trimesh, n_sample_points=10000):
18
  f32 = numpy.float32
 
107
  objamodel = objaverse.load_objects([objaid])[objaid]
108
  try:
109
  pc = trimesh_to_pc(trimesh.load(objamodel))
110
+ pc = random_sampling(pc, num_samples=5000)
111
  pc_list.append(pc.reshape([1, -1, pc.shape[-1]]))
112
  except:
113
  continue