Spaces:
Running on Zero
Running on Zero
padding_fix
#1
by
stephaniefu - opened
- demo_utils.py +10 -4
demo_utils.py
CHANGED
|
@@ -39,7 +39,7 @@ def image_to_video(image_path, output_path, fps):
|
|
| 39 |
|
| 40 |
img_array = np.array(img)
|
| 41 |
|
| 42 |
-
with imageio.get_writer(output_path, fps=fps, format='FFMPEG', codec='libx264', pixelformat='yuv420p') as writer:
|
| 43 |
writer.append_data(img_array)
|
| 44 |
|
| 45 |
return {
|
|
@@ -461,7 +461,10 @@ def process_video(video_path, setup, gazing_ratio=0.75, task_loss_requirement=0.
|
|
| 461 |
else:
|
| 462 |
mask_tensor = mask_2d
|
| 463 |
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
| 465 |
|
| 466 |
frame_tensor = video_viz[t]
|
| 467 |
frame_scaled = F.interpolate(frame_tensor.unsqueeze(0), size=(scale_h, scale_w), mode='bicubic', align_corners=False).squeeze().clamp(0, 1)
|
|
@@ -503,7 +506,10 @@ def process_video(video_path, setup, gazing_ratio=0.75, task_loss_requirement=0.
|
|
| 503 |
else:
|
| 504 |
mask_tensor_scale = mask_2d
|
| 505 |
|
| 506 |
-
|
|
|
|
|
|
|
|
|
|
| 507 |
|
| 508 |
frame_tensor_scale = video_viz[t]
|
| 509 |
frame_scaled_scale = F.interpolate(frame_tensor_scale.unsqueeze(0), size=(scale_h, scale_w), mode='bicubic', align_corners=False).squeeze().clamp(0, 1)
|
|
@@ -576,6 +582,6 @@ def process_video(video_path, setup, gazing_ratio=0.75, task_loss_requirement=0.
|
|
| 576 |
|
| 577 |
|
| 578 |
def save_video(frames, output_path, fps):
|
| 579 |
-
with imageio.get_writer(output_path, fps=fps, format='FFMPEG', codec='libx264', pixelformat='yuv420p') as writer:
|
| 580 |
for frame in frames:
|
| 581 |
writer.append_data(frame)
|
|
|
|
| 39 |
|
| 40 |
img_array = np.array(img)
|
| 41 |
|
| 42 |
+
with imageio.get_writer(output_path, fps=fps, format='FFMPEG', codec='libx264', pixelformat='yuv420p', macro_block_size=1) as writer:
|
| 43 |
writer.append_data(img_array)
|
| 44 |
|
| 45 |
return {
|
|
|
|
| 461 |
else:
|
| 462 |
mask_tensor = mask_2d
|
| 463 |
|
| 464 |
+
# Map mask through padded space then crop to original image dimensions
|
| 465 |
+
H_pad, W_pad = nh * 224, nw * 224
|
| 466 |
+
mask_full = F.interpolate(mask_tensor.unsqueeze(0).unsqueeze(0).float(), size=(H_pad, W_pad), mode='nearest')[0, 0]
|
| 467 |
+
mask_resized = F.interpolate(mask_full[:H, :W].unsqueeze(0).unsqueeze(0), size=(scale_h, scale_w), mode='nearest')[0, 0]
|
| 468 |
|
| 469 |
frame_tensor = video_viz[t]
|
| 470 |
frame_scaled = F.interpolate(frame_tensor.unsqueeze(0), size=(scale_h, scale_w), mode='bicubic', align_corners=False).squeeze().clamp(0, 1)
|
|
|
|
| 506 |
else:
|
| 507 |
mask_tensor_scale = mask_2d
|
| 508 |
|
| 509 |
+
# Map mask through padded space then crop to original image dimensions
|
| 510 |
+
H_pad, W_pad = nh * 224, nw * 224
|
| 511 |
+
mask_full_scale = F.interpolate(mask_tensor_scale.unsqueeze(0).unsqueeze(0).float(), size=(H_pad, W_pad), mode='nearest')[0, 0]
|
| 512 |
+
mask_resized_scale = F.interpolate(mask_full_scale[:H, :W].unsqueeze(0).unsqueeze(0), size=(scale_h, scale_w), mode='nearest')[0, 0]
|
| 513 |
|
| 514 |
frame_tensor_scale = video_viz[t]
|
| 515 |
frame_scaled_scale = F.interpolate(frame_tensor_scale.unsqueeze(0), size=(scale_h, scale_w), mode='bicubic', align_corners=False).squeeze().clamp(0, 1)
|
|
|
|
| 582 |
|
| 583 |
|
| 584 |
def save_video(frames, output_path, fps):
|
| 585 |
+
with imageio.get_writer(output_path, fps=fps, format='FFMPEG', codec='libx264', pixelformat='yuv420p', macro_block_size=1) as writer:
|
| 586 |
for frame in frames:
|
| 587 |
writer.append_data(frame)
|