luh1124 commited on
Commit
914fb3d
Β·
1 Parent(s): 3b42013

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

Files changed (1) hide show
  1. app.py +22 -21
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
- 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
- roll_frames, hdri_frames = pipe.render_hdri_rotation_video(
539
- slat, hdri_np,
540
- num_frames=int(num_hdri),
541
- yaw_deg=float(yaw), pitch_deg=float(pitch),
542
- fov=float(fov), radius=float(radius),
543
- full_video=True,
544
- shadow_video=True,
545
- bg_color=(1, 1, 1),
546
- verbose=True,
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))