Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -313,6 +313,9 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
| 313 |
# Define a directory to save the JPEG images
|
| 314 |
frames_output_dir = "frames_output_images"
|
| 315 |
os.makedirs(frames_output_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
# Initialize a list to store file paths of saved images
|
| 318 |
jpeg_images = []
|
|
@@ -354,8 +357,13 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
| 354 |
available_frames_to_check.append(f"frame_{out_frame_idx}.jpg")
|
| 355 |
|
| 356 |
# Save the raw binary mask as a separate image
|
| 357 |
-
mask_filename = os.path.join(
|
| 358 |
-
binary_mask = (out_mask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
mask_image = Image.fromarray(binary_mask)
|
| 360 |
mask_image.save(mask_filename) # Save the mask as a JPEG
|
| 361 |
masks_frames.append(mask_filename) # Append to the list of masks
|
|
|
|
| 313 |
# Define a directory to save the JPEG images
|
| 314 |
frames_output_dir = "frames_output_images"
|
| 315 |
os.makedirs(frames_output_dir, exist_ok=True)
|
| 316 |
+
|
| 317 |
+
mask_frames_output_dir = "mask_frames_output_images"
|
| 318 |
+
os.makedirs(mask_frames_output_dir, exist_ok=True)
|
| 319 |
|
| 320 |
# Initialize a list to store file paths of saved images
|
| 321 |
jpeg_images = []
|
|
|
|
| 357 |
available_frames_to_check.append(f"frame_{out_frame_idx}.jpg")
|
| 358 |
|
| 359 |
# Save the raw binary mask as a separate image
|
| 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
|