Spaces:
Runtime error
Runtime error
fix: SAM2 post_process_masks signature + use text_labels (transformers 5.8.1 compat)
Browse files
app.py
CHANGED
|
@@ -205,6 +205,10 @@ def analyze(image_base64: str) -> dict:
|
|
| 205 |
sam2_model.to(device)
|
| 206 |
segments = []
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
for box, label, score in zip(boxes, labels, scores):
|
| 209 |
if len(segments) >= MAX_SEGMENTS:
|
| 210 |
break
|
|
|
|
| 205 |
sam2_model.to(device)
|
| 206 |
segments = []
|
| 207 |
|
| 208 |
+
# Sort by score descending so highest-confidence detections survive MAX_SEGMENTS cap.
|
| 209 |
+
sorted_detections = sorted(zip(scores, boxes, labels), reverse=True)
|
| 210 |
+
scores, boxes, labels = zip(*sorted_detections) if sorted_detections else ([], [], [])
|
| 211 |
+
|
| 212 |
for box, label, score in zip(boxes, labels, scores):
|
| 213 |
if len(segments) >= MAX_SEGMENTS:
|
| 214 |
break
|