Instructions to use milaithx/sam2.1-hiera-base-plus with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use milaithx/sam2.1-hiera-base-plus with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("mask-generation", model="milaithx/sam2.1-hiera-base-plus")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("milaithx/sam2.1-hiera-base-plus") model = AutoModel.from_pretrained("milaithx/sam2.1-hiera-base-plus", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit History
-
Read config from inside inputs, not top-level request body
Oleksandr TernovyiTop-level keys outside 'inputs' aren't reliably forwarded by the HF inference toolkit wrapper, so config.mode was never seen server-side and every request silently fell back to automatic mode.0a2b18e -
Support config-driven mode: automatic or point-prompt segmentation
Oleksandr TernovyiAutomatic mask generation can't cleanly isolate the trench — it's internally heterogeneous (dirt, shadow, segments, water), so it either fragments or merges with surrounding terrain regardless of tuning. Add a 'point' mode using SAM2ImagePredictor so a specific point (e.g. a user click) can be segmented directly, and move all generator/predictor parameters into a generic 'config' dict from the request instead of hardcoding them in the handler.cca971b -
Lower points_per_side to 16 to cut CPU inference latency
Oleksandr TernovyiEndpoint lacks the compiled SAM2 _C extension, so mask decode/NMS runs on a slow CPU fallback path; one request was taking ~11 minutes at points_per_side=32, causing requests to queue. Halving grid density roughly quarters per-request cost at the expense of coarser coverage.804a7a2 -
Revert mask generator density bump, keep on CPU-friendly settings
Oleksandr Ternovyipoints_per_side=64 + crop_n_layers=1 multiplied per-image inference cost several times over; this endpoint runs on CPU without the compiled SAM2 _C extension, so requests were hanging. Trench shape-filtering itself is cheap numpy work on already-computed masks, so it stays.ef3ab6b -
Filter automatic masks for trench-like shapes
Oleksandr TernovyiAuto mask generator returned generic blobs covering the whole excavated corridor; add shape-based filtering (aspect ratio + bbox fill ratio) to isolate thin elongated trench segments, returned separately as trench_masks.0b596f8
-
requirements: sam2 to segment all objects
Oleksandr Ternovyif97373f -
fix: hardcode model ID, sam2 from_pretrained does not accept local path
Oleksandr Ternovyifa691c7 -
requirements: sam2 from source only
Oleksandr Ternovyi50268e2 -
add custom endpoint handler for SAM2.1
Oleksandr Ternovyi4ee98e8