RF Segment Anything

raw JSON →
1.0 verified Sat May 09 auth: no python

RF Segment Anything (rf-segment-anything) provides a simple API to run Meta's Segment Anything Model (SAM) for image segmentation with just a few lines of code. Version 1.0 is currently available. Release cadence is unknown; the library appears to be in early active development.

pip install rf-segment-anything
error ModuleNotFoundError: No module named 'rf_segment_anything'
cause Package not installed or installed in a different environment.
fix
Run pip install rf-segment-anything in the correct Python environment.
error AttributeError: module 'rf_segment_anything' has no attribute 'Segmentation'
cause Importing the package instead of the class.
fix
Use from rf_segment_anything import Segmentation.
error RuntimeError: Model vit_h not found. Available: vit_b, vit_l, vit_h
cause Typo in model name or model not downloaded.
fix
Check model name (exact string) and ensure internet connection for first-time download.
gotcha Model weights are downloaded automatically on first use to ~/.cache/torch/hub/checkpoints/. Ensure you have disk space and network access.
fix Pre-download weights manually or set environment variable TORCH_HOME to a custom directory.
gotcha The segment() method returns a dictionary with keys 'masks', 'boxes', etc. Do not expect a single mask array; iterate over results.
fix Access result['masks'] for the list of masks.
deprecated The parameter 'model_type' in load_model() may be renamed to 'model_name' in future releases.
fix Use the correct parameter name for your version; check documentation before upgrading.

Instantiate a Segmentation object, load a pre-trained model (e.g., vit_h), and call segment() on an image path or numpy array.

from rf_segment_anything import Segmentation

segmenter = Segmentation()
segmenter.load_model("vit_h")

# Use an image path or numpy array
result = segmenter.segment("path/to/image.jpg")
print(result)