MARS 1.0
Precise Point-Based Object Segmentation in Images
2 min read
The MARS 1.0 model handles image object segmentation using positive point prompts. It takes an RGB image and point coordinates inside the object as input, outputting a binary mask at the original image resolution. The model architecture features a SAM ViT-H image encoder (Segment Anything Model, a large variant of the base segmentation model), a ConvNeXt-Small branch for RGB images, and a combined ViT-L/DPT decoder. The model is convenient because it includes all components in a single checkpoint and requires no separate downloads.
Key features
- All parameters in a single file without needing to download additional components.
- Support for running on both a GPU via CUDA and a CPU.
- Automatic image preprocessing with resizing and normalization directly in the code.
- Caching of image features for fast processing of new point sets on the same frame.
What you can do
- Isolate a target object in a photo by specifying a few points inside it.
- Create a foreground mask for subsequent background removal or editing.
- Process an image collection in a Python script to automate computer vision tasks.
Example
import numpy as np
from PIL import Image
from huggingface_hub import hf_hub_download
from mars import build_mars, MarsPredictor
checkpoint = hf_hub_download(repo_id="RawmanticAI/MARS1.0", filename="mars1.0.pth")
model = build_mars(checkpoint=checkpoint, device="cuda").eval()
predictor = MarsPredictor(model, preprocessing="project")
image = np.array(Image.open("examples/images/person.jpg").convert("RGB"))
predictor.set_image(image)
points = np.array([[245, 180], [225, 480], [265, 480]], dtype=np.float32)
masks, _ = predictor.predict(points, mask_threshold=0.5)
Image.fromarray(masks[0].astype(np.uint8) * 255).save("mask.png")Read more
DetailsCheckpoint: mars1.0.pth in PyTorch state_dict format.
Architecture: SAM ViT-H, ConvNeXt-Small, and a combined ViT-L/DPT decoder.
Inputs: RGB uint8 images and point coordinates at the original resolution.










Comments