(images)
| 179 | |
| 180 | |
| 181 | def make3d(images): |
| 182 | |
| 183 | images = np.asarray(images, dtype=np.float32) / 255.0 |
| 184 | images = torch.from_numpy(images).permute(2, 0, 1).contiguous().float() # (3, 960, 640) |
| 185 | images = rearrange(images, 'c (n h) (m w) -> (n m) c h w', n=3, m=2) # (6, 3, 320, 320) |
| 186 | |
| 187 | input_cameras = get_zero123plus_input_cameras(batch_size=1, radius=4.0).to(device1) |
| 188 | render_cameras = get_render_cameras( |
| 189 | batch_size=1, radius=4.5, elevation=20.0, is_flexicubes=IS_FLEXICUBES).to(device1) |
| 190 | |
| 191 | images = images.unsqueeze(0).to(device1) |
| 192 | images = v2.functional.resize(images, (320, 320), interpolation=3, antialias=True).clamp(0, 1) |
| 193 | |
| 194 | mesh_fpath = tempfile.NamedTemporaryFile(suffix=f".obj", delete=False).name |
| 195 | print(mesh_fpath) |
| 196 | mesh_basename = os.path.basename(mesh_fpath).split('.')[0] |
| 197 | mesh_dirname = os.path.dirname(mesh_fpath) |
| 198 | video_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.mp4") |
| 199 | |
| 200 | with torch.no_grad(): |
| 201 | # get triplane |
| 202 | planes = model.forward_planes(images, input_cameras) |
| 203 | |
| 204 | # get video |
| 205 | chunk_size = 20 if IS_FLEXICUBES else 1 |
| 206 | render_size = 384 |
| 207 | |
| 208 | frames = [] |
| 209 | for i in tqdm(range(0, render_cameras.shape[1], chunk_size)): |
| 210 | if IS_FLEXICUBES: |
| 211 | frame = model.forward_geometry( |
| 212 | planes, |
| 213 | render_cameras[:, i:i+chunk_size], |
| 214 | render_size=render_size, |
| 215 | )['img'] |
| 216 | else: |
| 217 | frame = model.synthesizer( |
| 218 | planes, |
| 219 | cameras=render_cameras[:, i:i+chunk_size], |
| 220 | render_size=render_size, |
| 221 | )['images_rgb'] |
| 222 | frames.append(frame) |
| 223 | frames = torch.cat(frames, dim=1) |
| 224 | |
| 225 | images_to_video( |
| 226 | frames[0], |
| 227 | video_fpath, |
| 228 | fps=30, |
| 229 | ) |
| 230 | |
| 231 | print(f"Video saved to {video_fpath}") |
| 232 | |
| 233 | mesh_fpath, mesh_glb_fpath = make_mesh(mesh_fpath, planes) |
| 234 | |
| 235 | return video_fpath, mesh_fpath, mesh_glb_fpath |
| 236 | |
| 237 | |
| 238 | import gradio as gr |
nothing calls this directly
no test coverage detected