eliphatfs commited on
Commit
71bd9a3
·
1 Parent(s): c3cc2f4

Update support library.

Browse files
openshape/demo/misc_utils.py CHANGED
@@ -98,11 +98,11 @@ def trimesh_to_pc(scene_or_mesh):
98
  return model_to_pc(scene_or_mesh, 10000)
99
 
100
 
101
- def input_3d_shape():
102
- objaid = st.text_input("Enter an Objaverse ID")
103
- model = st.file_uploader("Or upload a model (.glb/.obj/.ply)")
104
- npy = st.file_uploader("Or upload a point cloud numpy array (.npy of Nx3 XYZ or Nx6 XYZRGB)")
105
- swap_yz_axes = st.checkbox("Swap Y/Z axes of input (Y is up for OpenShape)")
106
  f32 = numpy.float32
107
 
108
  def load_data(prog):
@@ -122,12 +122,13 @@ def input_3d_shape():
122
  prog.progress(0.25, "Preprocessing Point Cloud")
123
  assert pc.ndim == 2, "invalid pc shape: ndim = %d != 2" % pc.ndim
124
  assert pc.shape[1] in [3, 6], "invalid pc shape: should have 3/6 channels, got %d" % pc.shape[1]
 
125
  if swap_yz_axes:
126
  pc[:, [1, 2]] = pc[:, [2, 1]]
127
  pc[:, :3] = pc[:, :3] - numpy.mean(pc[:, :3], axis=0)
128
  pc[:, :3] = pc[:, :3] / numpy.linalg.norm(pc[:, :3], axis=-1).max()
129
  if pc.shape[1] == 3:
130
- pc = numpy.concatenate([pc, numpy.ones_like(pc)], axis=-1)
131
  prog.progress(0.27, "Normalized Point Cloud")
132
  if pc.shape[0] > 10000:
133
  pc = pc[numpy.random.permutation(len(pc))[:10000]]
 
98
  return model_to_pc(scene_or_mesh, 10000)
99
 
100
 
101
+ def input_3d_shape(key=None):
102
+ objaid = st.text_input("Enter an Objaverse ID", key=key)
103
+ model = st.file_uploader("Or upload a model (.glb/.obj/.ply)", key=key)
104
+ npy = st.file_uploader("Or upload a point cloud numpy array (.npy of Nx3 XYZ or Nx6 XYZRGB)", key=key)
105
+ swap_yz_axes = st.checkbox("Swap Y/Z axes of input (Y is up for OpenShape)", key=key)
106
  f32 = numpy.float32
107
 
108
  def load_data(prog):
 
122
  prog.progress(0.25, "Preprocessing Point Cloud")
123
  assert pc.ndim == 2, "invalid pc shape: ndim = %d != 2" % pc.ndim
124
  assert pc.shape[1] in [3, 6], "invalid pc shape: should have 3/6 channels, got %d" % pc.shape[1]
125
+ pc = pc.astype(f32)
126
  if swap_yz_axes:
127
  pc[:, [1, 2]] = pc[:, [2, 1]]
128
  pc[:, :3] = pc[:, :3] - numpy.mean(pc[:, :3], axis=0)
129
  pc[:, :3] = pc[:, :3] / numpy.linalg.norm(pc[:, :3], axis=-1).max()
130
  if pc.shape[1] == 3:
131
+ pc = numpy.concatenate([pc, numpy.ones_like(pc) * 0.4], axis=-1)
132
  prog.progress(0.27, "Normalized Point Cloud")
133
  if pc.shape[0] > 10000:
134
  pc = pc[numpy.random.permutation(len(pc))[:10000]]
openshape/demo/sd_pc2img.py CHANGED
@@ -27,7 +27,7 @@ def pc_to_image(pc_encoder: torch.nn.Module, pc, prompt, noise_level, width, hei
27
  ref_dev = next(pc_encoder.parameters()).device
28
  enc = pc_encoder(torch.tensor(pc.T[None], device=ref_dev))
29
  return pipe(
30
- prompt="best quality, super high resolution, " + prompt,
31
  negative_prompt="cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
32
  image=torch.nn.functional.normalize(enc, dim=-1) * (768 ** 0.5) / 2,
33
  width=width, height=height,
 
27
  ref_dev = next(pc_encoder.parameters()).device
28
  enc = pc_encoder(torch.tensor(pc.T[None], device=ref_dev))
29
  return pipe(
30
+ prompt=', '.join(["best quality", "super high resolution"] + ([prompt] if prompt else [])),
31
  negative_prompt="cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
32
  image=torch.nn.functional.normalize(enc, dim=-1) * (768 ** 0.5) / 2,
33
  width=width, height=height,