Spaces:
Runtime error
Runtime error
Anigor66 commited on
Commit ·
8cb9ee2
1
Parent(s): 9b35ab3
Lowered threshold
Browse files
app.py
CHANGED
|
@@ -59,11 +59,11 @@ print("✓ SamPredictor initialized for interactive segmentation")
|
|
| 59 |
mask_generator = SamAutomaticMaskGenerator(
|
| 60 |
model=sam,
|
| 61 |
points_per_side=32, # Grid density (32x32 = 1024 points)
|
| 62 |
-
pred_iou_thresh=0.
|
| 63 |
-
stability_score_thresh=0.
|
| 64 |
crop_n_layers=0, # Disable multi-scale crops to avoid IndexError
|
| 65 |
crop_n_points_downscale_factor=2,
|
| 66 |
-
min_mask_region_area=
|
| 67 |
)
|
| 68 |
print("✓ SamAutomaticMaskGenerator initialized for automatic segmentation")
|
| 69 |
print("✓ MedSAM model loaded successfully!")
|
|
@@ -414,6 +414,19 @@ def generate_auto_masks(image, request_json):
|
|
| 414 |
masks = mask_generator.generate(image_array)
|
| 415 |
|
| 416 |
print(f"Generated {len(masks)} masks")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
# Convert masks to JSON-serializable format
|
| 419 |
masks_output = []
|
|
|
|
| 59 |
mask_generator = SamAutomaticMaskGenerator(
|
| 60 |
model=sam,
|
| 61 |
points_per_side=32, # Grid density (32x32 = 1024 points)
|
| 62 |
+
pred_iou_thresh=0.7, # IoU threshold for filtering (lowered from 0.88)
|
| 63 |
+
stability_score_thresh=0.7, # Stability threshold (lowered from 0.95 - was too strict)
|
| 64 |
crop_n_layers=0, # Disable multi-scale crops to avoid IndexError
|
| 65 |
crop_n_points_downscale_factor=2,
|
| 66 |
+
min_mask_region_area=0 # Minimum mask area (lowered from 100 to allow small masks)
|
| 67 |
)
|
| 68 |
print("✓ SamAutomaticMaskGenerator initialized for automatic segmentation")
|
| 69 |
print("✓ MedSAM model loaded successfully!")
|
|
|
|
| 414 |
masks = mask_generator.generate(image_array)
|
| 415 |
|
| 416 |
print(f"Generated {len(masks)} masks")
|
| 417 |
+
if len(masks) > 0:
|
| 418 |
+
# Log some stats about the masks
|
| 419 |
+
areas = [m['area'] for m in masks]
|
| 420 |
+
ious = [m['predicted_iou'] for m in masks]
|
| 421 |
+
stabilities = [m['stability_score'] for m in masks]
|
| 422 |
+
print(f" Area range: {min(areas)} - {max(areas)} pixels")
|
| 423 |
+
print(f" IoU range: {min(ious):.3f} - {max(ious):.3f}")
|
| 424 |
+
print(f" Stability range: {min(stabilities):.3f} - {max(stabilities):.3f}")
|
| 425 |
+
else:
|
| 426 |
+
print(" WARNING: No masks generated! This could mean:")
|
| 427 |
+
print(" - Image is too uniform/simple")
|
| 428 |
+
print(" - Thresholds are still too strict")
|
| 429 |
+
print(" - Image size is too small or too large")
|
| 430 |
|
| 431 |
# Convert masks to JSON-serializable format
|
| 432 |
masks_output = []
|