Spaces:
Runtime error
Runtime error
amankishore
commited on
Commit
·
fad0371
1
Parent(s):
c58b594
Better mesh
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ from typing import Union
|
|
19 |
from shap_e.diffusion.sample import sample_latents
|
20 |
from shap_e.diffusion.gaussian_diffusion import diffusion_from_config
|
21 |
from shap_e.models.download import load_model, load_config
|
22 |
-
from shap_e.util.notebooks import create_pan_cameras, decode_latent_images
|
23 |
|
24 |
from shap_e.models.nn.camera import DifferentiableCameraBatch, DifferentiableProjectiveCamera
|
25 |
from shap_e.models.transmitter.base import Transmitter, VectorDecoder
|
@@ -45,22 +45,6 @@ def set_state(s):
|
|
45 |
def get_state():
|
46 |
return state
|
47 |
|
48 |
-
@torch.no_grad()
|
49 |
-
def decode_latent_images_foo(
|
50 |
-
xm: Union[Transmitter, VectorDecoder],
|
51 |
-
latent: torch.Tensor,
|
52 |
-
cameras: DifferentiableCameraBatch,
|
53 |
-
rendering_mode: str = "stf",
|
54 |
-
):
|
55 |
-
decoded = xm.renderer.render_views(
|
56 |
-
AttrDict(cameras=cameras),
|
57 |
-
params=(xm.encoder if isinstance(xm, Transmitter) else xm).bottleneck_to_params(
|
58 |
-
latent[None]
|
59 |
-
),
|
60 |
-
options=AttrDict(rendering_mode=rendering_mode, render_with_direction=False),
|
61 |
-
)
|
62 |
-
return decoded
|
63 |
-
|
64 |
def to_video(frames: list[Image.Image], fps: int = 5) -> str:
|
65 |
out_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
66 |
writer = imageio.get_writer(out_file.name, format='FFMPEG', fps=fps)
|
@@ -113,18 +97,8 @@ def generate_3D(input, grid_size=64):
|
|
113 |
|
114 |
cameras = create_pan_cameras(size, device)
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
rm=x['raw_meshes'][0]
|
119 |
-
|
120 |
-
rm.vertex_channels["R"]=mesh.vertex_colors[:,0]
|
121 |
-
rm.vertex_channels["G"]=mesh.vertex_colors[:,1]
|
122 |
-
rm.vertex_channels["B"]=mesh.vertex_colors[:,2]
|
123 |
-
|
124 |
-
tm=rm.tri_mesh()
|
125 |
-
|
126 |
-
with open("/tmp/mesh.ply",'wb') as f:
|
127 |
-
tm.write_ply(f)
|
128 |
|
129 |
|
130 |
set_state('Converting to point cloud...')
|
|
|
19 |
from shap_e.diffusion.sample import sample_latents
|
20 |
from shap_e.diffusion.gaussian_diffusion import diffusion_from_config
|
21 |
from shap_e.models.download import load_model, load_config
|
22 |
+
from shap_e.util.notebooks import create_pan_cameras, decode_latent_images, decode_latent_mesh
|
23 |
|
24 |
from shap_e.models.nn.camera import DifferentiableCameraBatch, DifferentiableProjectiveCamera
|
25 |
from shap_e.models.transmitter.base import Transmitter, VectorDecoder
|
|
|
45 |
def get_state():
|
46 |
return state
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def to_video(frames: list[Image.Image], fps: int = 5) -> str:
|
49 |
out_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
50 |
writer = imageio.get_writer(out_file.name, format='FFMPEG', fps=fps)
|
|
|
97 |
|
98 |
cameras = create_pan_cameras(size, device)
|
99 |
|
100 |
+
with open(f'/tmp/mesh.ply', 'wb') as f:
|
101 |
+
decode_latent_mesh(xm, latents[0]).tri_mesh().write_ply(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
|
104 |
set_state('Converting to point cloud...')
|