Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
e2bed97
1
Parent(s):
0ea4068
remove print
Browse files
app.py
CHANGED
|
@@ -499,8 +499,6 @@ def propagate_masks(GLOBAL_STATE: gr.State):
|
|
| 499 |
with torch.inference_mode():
|
| 500 |
for frame_idx, frame in enumerate(GLOBAL_STATE.video_frames):
|
| 501 |
pixel_values = None
|
| 502 |
-
print("inference_session.processed_frames", inference_session.processed_frames)
|
| 503 |
-
print("frame_idx", frame_idx)
|
| 504 |
if inference_session.processed_frames is None or frame_idx not in inference_session.processed_frames:
|
| 505 |
pixel_values = processor(images=frame, device="cuda", return_tensors="pt").pixel_values[0]
|
| 506 |
sam2_video_output = model(inference_session=inference_session, frame=pixel_values, frame_idx=frame_idx)
|
|
@@ -754,32 +752,17 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
|
|
| 754 |
out_path = "/tmp/sam2_playback.mp4"
|
| 755 |
# Prefer imageio with PyAV/ffmpeg to respect exact fps
|
| 756 |
try:
|
| 757 |
-
import
|
| 758 |
|
| 759 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 760 |
return out_path
|
| 761 |
except Exception as e:
|
| 762 |
-
print(f"Failed to render video with
|
| 763 |
-
|
| 764 |
-
try:
|
| 765 |
-
import imageio.v2 as imageio # type: ignore
|
| 766 |
-
|
| 767 |
-
imageio.mimsave(out_path, [fr[:, :, ::-1] for fr in frames_np], fps=fps)
|
| 768 |
-
return out_path
|
| 769 |
-
except Exception as e:
|
| 770 |
-
print(f"Failed to render video with imageio.v2: {e}")
|
| 771 |
-
try:
|
| 772 |
-
import cv2 # type: ignore
|
| 773 |
-
|
| 774 |
-
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 775 |
-
writer = cv2.VideoWriter(out_path, fourcc, fps, (w, h))
|
| 776 |
-
for fr_bgr in frames_np:
|
| 777 |
-
writer.write(fr_bgr)
|
| 778 |
-
writer.release()
|
| 779 |
-
return out_path
|
| 780 |
-
except Exception as e:
|
| 781 |
-
print(f"Failed to render video with cv2: {e}")
|
| 782 |
-
raise gr.Error(f"Failed to render video: {e}")
|
| 783 |
|
| 784 |
render_btn.click(_render_video, inputs=[GLOBAL_STATE], outputs=[playback_video])
|
| 785 |
|
|
|
|
| 499 |
with torch.inference_mode():
|
| 500 |
for frame_idx, frame in enumerate(GLOBAL_STATE.video_frames):
|
| 501 |
pixel_values = None
|
|
|
|
|
|
|
| 502 |
if inference_session.processed_frames is None or frame_idx not in inference_session.processed_frames:
|
| 503 |
pixel_values = processor(images=frame, device="cuda", return_tensors="pt").pixel_values[0]
|
| 504 |
sam2_video_output = model(inference_session=inference_session, frame=pixel_values, frame_idx=frame_idx)
|
|
|
|
| 752 |
out_path = "/tmp/sam2_playback.mp4"
|
| 753 |
# Prefer imageio with PyAV/ffmpeg to respect exact fps
|
| 754 |
try:
|
| 755 |
+
import cv2 # type: ignore
|
| 756 |
|
| 757 |
+
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 758 |
+
writer = cv2.VideoWriter(out_path, fourcc, fps, (w, h))
|
| 759 |
+
for fr_bgr in frames_np:
|
| 760 |
+
writer.write(fr_bgr)
|
| 761 |
+
writer.release()
|
| 762 |
return out_path
|
| 763 |
except Exception as e:
|
| 764 |
+
print(f"Failed to render video with cv2: {e}")
|
| 765 |
+
raise gr.Error(f"Failed to render video: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
|
| 767 |
render_btn.click(_render_video, inputs=[GLOBAL_STATE], outputs=[playback_video])
|
| 768 |
|