fix: enable gradients for texture baking in GLB export
Browse files- Removed @torch .no_grad() from generate_renderings to allow gradients for texture baking
- Added torch.no_grad() context managers around video rendering to save memory
- This fixes 'element 0 of tensors does not require grad' error during GLB export
app.py
CHANGED
|
@@ -471,7 +471,6 @@ def load_slat_file(
|
|
| 471 |
|
| 472 |
|
| 473 |
@_gpu(duration=600)
|
| 474 |
-
@torch.no_grad()
|
| 475 |
def generate_renderings(
|
| 476 |
asset_state: Dict[str, Any],
|
| 477 |
hdri_file_obj: Any,
|
|
@@ -519,32 +518,34 @@ def generate_renderings(
|
|
| 519 |
|
| 520 |
# ββ Render videos ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 521 |
progress(0.12, desc="Rendering camera-orbit videoβ¦")
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
|
|
|
| 532 |
p_cam = session_dir / "video_camera_orbit.mp4"
|
| 533 |
imageio.mimsave(p_cam, cam_frames, fps=int(fps))
|
| 534 |
del cam_frames
|
| 535 |
_free_cuda() # Free GPU mem temporarily while still in same CUDA context
|
| 536 |
|
| 537 |
progress(0.55, desc="Rendering HDRI-rotation videoβ¦")
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
|
|
|
| 548 |
p_hdri = session_dir / "video_hdri_rotation.mp4"
|
| 549 |
p_roll = session_dir / "video_env_roll.mp4"
|
| 550 |
imageio.mimsave(p_hdri, hdri_frames, fps=int(fps))
|
|
|
|
| 471 |
|
| 472 |
|
| 473 |
@_gpu(duration=600)
|
|
|
|
| 474 |
def generate_renderings(
|
| 475 |
asset_state: Dict[str, Any],
|
| 476 |
hdri_file_obj: Any,
|
|
|
|
| 518 |
|
| 519 |
# ββ Render videos ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 520 |
progress(0.12, desc="Rendering camera-orbit videoβ¦")
|
| 521 |
+
with torch.no_grad():
|
| 522 |
+
cam_frames = pipe.render_camera_path_video(
|
| 523 |
+
slat, hdri_np,
|
| 524 |
+
num_views=int(num_cam),
|
| 525 |
+
fov=float(fov), radius=float(radius),
|
| 526 |
+
hdri_rot_deg=float(hdri_rot),
|
| 527 |
+
full_video=True,
|
| 528 |
+
shadow_video=True,
|
| 529 |
+
bg_color=(1, 1, 1),
|
| 530 |
+
verbose=True,
|
| 531 |
+
)
|
| 532 |
p_cam = session_dir / "video_camera_orbit.mp4"
|
| 533 |
imageio.mimsave(p_cam, cam_frames, fps=int(fps))
|
| 534 |
del cam_frames
|
| 535 |
_free_cuda() # Free GPU mem temporarily while still in same CUDA context
|
| 536 |
|
| 537 |
progress(0.55, desc="Rendering HDRI-rotation videoβ¦")
|
| 538 |
+
with torch.no_grad():
|
| 539 |
+
roll_frames, hdri_frames = pipe.render_hdri_rotation_video(
|
| 540 |
+
slat, hdri_np,
|
| 541 |
+
num_frames=int(num_hdri),
|
| 542 |
+
yaw_deg=float(yaw), pitch_deg=float(pitch),
|
| 543 |
+
fov=float(fov), radius=float(radius),
|
| 544 |
+
full_video=True,
|
| 545 |
+
shadow_video=True,
|
| 546 |
+
bg_color=(1, 1, 1),
|
| 547 |
+
verbose=True,
|
| 548 |
+
)
|
| 549 |
p_hdri = session_dir / "video_hdri_rotation.mp4"
|
| 550 |
p_roll = session_dir / "video_env_roll.mp4"
|
| 551 |
imageio.mimsave(p_hdri, hdri_frames, fps=int(fps))
|