Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -343,6 +343,18 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
343 |
for out_obj_id, out_mask in video_segments[out_frame_idx].items():
|
344 |
show_mask(out_mask, plt.gca(), obj_id=out_obj_id)
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
# Define the output filename and save the figure as a JPEG file
|
347 |
output_filename = os.path.join(frames_output_dir, f"frame_{out_frame_idx}.jpg")
|
348 |
plt.savefig(output_filename, format='jpg')
|
@@ -356,17 +368,7 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
356 |
if f"frame_{out_frame_idx}.jpg" not in available_frames_to_check:
|
357 |
available_frames_to_check.append(f"frame_{out_frame_idx}.jpg")
|
358 |
|
359 |
-
|
360 |
-
mask_filename = os.path.join(mask_frames_output_dir, f"mask_{out_frame_idx}.jpg")
|
361 |
-
binary_mask = np.squeeze(out_mask) # Ensure the mask is 2D
|
362 |
-
binary_mask = (binary_mask * 255).astype(np.uint8) # Scale mask to 0-255
|
363 |
-
|
364 |
-
if binary_mask.ndim != 2: # Ensure it's 2D for PIL
|
365 |
-
raise ValueError(f"Mask has invalid dimensions: {binary_mask.shape}")
|
366 |
-
|
367 |
-
mask_image = Image.fromarray(binary_mask)
|
368 |
-
mask_image.save(mask_filename) # Save the mask as a JPEG
|
369 |
-
masks_frames.append(mask_filename) # Append to the list of masks
|
370 |
|
371 |
torch.cuda.empty_cache()
|
372 |
print(f"JPEG_IMAGES: {jpeg_images}")
|
|
|
343 |
for out_obj_id, out_mask in video_segments[out_frame_idx].items():
|
344 |
show_mask(out_mask, plt.gca(), obj_id=out_obj_id)
|
345 |
|
346 |
+
# Save the raw binary mask as a separate image
|
347 |
+
mask_filename = os.path.join(mask_frames_output_dir, f"mask_{out_frame_idx}.jpg")
|
348 |
+
binary_mask = np.squeeze(out_mask) # Ensure the mask is 2D
|
349 |
+
binary_mask = (binary_mask * 255).astype(np.uint8) # Scale mask to 0-255
|
350 |
+
|
351 |
+
if binary_mask.ndim != 2: # Ensure it's 2D for PIL
|
352 |
+
raise ValueError(f"Mask has invalid dimensions: {binary_mask.shape}")
|
353 |
+
|
354 |
+
mask_image = Image.fromarray(binary_mask)
|
355 |
+
mask_image.save(mask_filename) # Save the mask as a JPEG
|
356 |
+
masks_frames.append(mask_filename) # Append to the list of masks
|
357 |
+
|
358 |
# Define the output filename and save the figure as a JPEG file
|
359 |
output_filename = os.path.join(frames_output_dir, f"frame_{out_frame_idx}.jpg")
|
360 |
plt.savefig(output_filename, format='jpg')
|
|
|
368 |
if f"frame_{out_frame_idx}.jpg" not in available_frames_to_check:
|
369 |
available_frames_to_check.append(f"frame_{out_frame_idx}.jpg")
|
370 |
|
371 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
|
373 |
torch.cuda.empty_cache()
|
374 |
print(f"JPEG_IMAGES: {jpeg_images}")
|