mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-13 04:25:32 +08:00
refactor(compressors): migrate to centralized model loaders
- Refactor model_loader.py: improve return type annotations from tuple[Any, Any] to tuple[AutoImageProcessor, AutoModel] - Refactor proposal/core.py: add input validation for mask array dimensionality, handle 2D masks and batch dimensions gracefully - Refactor proposal_segament.ipynb: replace inline model loading with centralized load_owlv2_model() and load_sam_model() functions, use batched detect_objects_batch() and generate_proposals_batch() APIs
This commit is contained in:
@@ -205,16 +205,14 @@ def _masks_to_proposals(masks: Any) -> list[dict[str, Any]]:
|
||||
if mask_array is None:
|
||||
return []
|
||||
|
||||
# Ensure 3D: [num_masks, H, W]
|
||||
if mask_array.ndim == 2:
|
||||
mask_array = np.expand_dims(mask_array, axis=0)
|
||||
|
||||
if mask_array.ndim != 3:
|
||||
if mask_array.ndim < 2:
|
||||
return []
|
||||
|
||||
# Remove batch dim if present: [1, num_masks, H, W] → [num_masks, H, W]
|
||||
if mask_array.ndim == 3 and mask_array.shape[0] == 1:
|
||||
mask_array = mask_array[0]
|
||||
if mask_array.ndim == 2:
|
||||
mask_array = np.expand_dims(mask_array, axis=0)
|
||||
else:
|
||||
height, width = mask_array.shape[-2], mask_array.shape[-1]
|
||||
mask_array = mask_array.reshape(-1, height, width)
|
||||
|
||||
proposals: list[dict[str, Any]] = []
|
||||
for single_mask in mask_array:
|
||||
|
||||
Reference in New Issue
Block a user