Update utils/segmentation.py
Browse files- utils/segmentation.py +13 -4
utils/segmentation.py
CHANGED
|
@@ -8,8 +8,9 @@
|
|
| 8 |
-------
|
| 9 |
segment_person_hq(image, predictor, fallback_enabled=True) β np.ndarray
|
| 10 |
segment_person_hq_original(image, predictor, fallback_enabled=True) β np.ndarray
|
|
|
|
| 11 |
|
| 12 |
-
Everything else is prefixed
|
| 13 |
"""
|
| 14 |
|
| 15 |
from __future__ import annotations
|
|
@@ -22,6 +23,13 @@
|
|
| 22 |
|
| 23 |
log = logging.getLogger(__name__)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# ============================================================================
|
| 26 |
# TUNABLE CONSTANTS
|
| 27 |
# ============================================================================
|
|
@@ -40,6 +48,7 @@
|
|
| 40 |
__all__ = [
|
| 41 |
"segment_person_hq",
|
| 42 |
"segment_person_hq_original",
|
|
|
|
| 43 |
]
|
| 44 |
|
| 45 |
# ============================================================================
|
|
@@ -56,7 +65,7 @@ def segment_person_hq(image: np.ndarray, predictor: Any, fallback_enabled: bool
|
|
| 56 |
return segment_person_hq_original(image, predictor, fallback_enabled)
|
| 57 |
|
| 58 |
if image is None or image.size == 0:
|
| 59 |
-
raise
|
| 60 |
|
| 61 |
# 1) β SAM-2 path -------------------------------------------------------
|
| 62 |
if predictor and hasattr(predictor, "set_image") and hasattr(predictor, "predict"):
|
|
@@ -93,7 +102,7 @@ def segment_person_hq_original(image: np.ndarray, predictor: Any, fallback_enabl
|
|
| 93 |
Very first implementation kept for rollback. Fewer smarts, still robust.
|
| 94 |
"""
|
| 95 |
if image is None or image.size == 0:
|
| 96 |
-
raise
|
| 97 |
|
| 98 |
try:
|
| 99 |
if predictor and hasattr(predictor, "set_image") and hasattr(predictor, "predict"):
|
|
@@ -290,4 +299,4 @@ def _geometric_person_mask(image: np.ndarray) -> np.ndarray:
|
|
| 290 |
|
| 291 |
def _auto_refine_mask_iteratively(image, mask, predictor, max_iterations=1):
|
| 292 |
# Simple one-pass hook (full version lives in refinement.py)
|
| 293 |
-
return mask
|
|
|
|
| 8 |
-------
|
| 9 |
segment_person_hq(image, predictor, fallback_enabled=True) β np.ndarray
|
| 10 |
segment_person_hq_original(image, predictor, fallback_enabled=True) β np.ndarray
|
| 11 |
+
SegmentationError - Custom exception for segmentation errors
|
| 12 |
|
| 13 |
+
Everything else is prefixed "_" and considered private.
|
| 14 |
"""
|
| 15 |
|
| 16 |
from __future__ import annotations
|
|
|
|
| 23 |
|
| 24 |
log = logging.getLogger(__name__)
|
| 25 |
|
| 26 |
+
# ============================================================================
|
| 27 |
+
# CUSTOM EXCEPTION
|
| 28 |
+
# ============================================================================
|
| 29 |
+
class SegmentationError(Exception):
|
| 30 |
+
"""Custom exception for segmentation-related errors"""
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
# ============================================================================
|
| 34 |
# TUNABLE CONSTANTS
|
| 35 |
# ============================================================================
|
|
|
|
| 48 |
__all__ = [
|
| 49 |
"segment_person_hq",
|
| 50 |
"segment_person_hq_original",
|
| 51 |
+
"SegmentationError",
|
| 52 |
]
|
| 53 |
|
| 54 |
# ============================================================================
|
|
|
|
| 65 |
return segment_person_hq_original(image, predictor, fallback_enabled)
|
| 66 |
|
| 67 |
if image is None or image.size == 0:
|
| 68 |
+
raise SegmentationError("Invalid input image")
|
| 69 |
|
| 70 |
# 1) β SAM-2 path -------------------------------------------------------
|
| 71 |
if predictor and hasattr(predictor, "set_image") and hasattr(predictor, "predict"):
|
|
|
|
| 102 |
Very first implementation kept for rollback. Fewer smarts, still robust.
|
| 103 |
"""
|
| 104 |
if image is None or image.size == 0:
|
| 105 |
+
raise SegmentationError("Invalid input image")
|
| 106 |
|
| 107 |
try:
|
| 108 |
if predictor and hasattr(predictor, "set_image") and hasattr(predictor, "predict"):
|
|
|
|
| 299 |
|
| 300 |
def _auto_refine_mask_iteratively(image, mask, predictor, max_iterations=1):
|
| 301 |
# Simple one-pass hook (full version lives in refinement.py)
|
| 302 |
+
return mask
|