Sam V2.1 Hiera Large
SAM v2, the next-gen segmentation model from Meta AI, revolutionizes computer vision. Building on SAM's success, it excels at accurately segmenting objects in images, offering robust and efficient solutions for various visual contexts.
API
If you're looking for an API, you can choose from your desired programming language.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import base64
# Use this function to convert an image file from the filesystem to base64
def image_file_to_base64(image_path):
with open(image_path, 'rb') as f:
image_data = f.read()
return base64.b64encode(image_data).decode('utf-8')
# Use this function to fetch an image from a URL and convert it to base64
def image_url_to_base64(image_url):
response = requests.get(image_url)
image_data = response.content
return base64.b64encode(image_data).decode('utf-8')
# Use this function to convert a list of image URLs to base64
def image_urls_to_base64(image_urls):
return [image_url_to_base64(url) for url in image_urls]
api_key = "YOUR_API_KEY"
url = "https://api.segmind.com/v1/sam-v21-hiera-large"
# Request payload
data = {
"image": image_url_to_base64("https://huggingface.co/datasets/hf-internal-testing/sam2-fixtures/resolve/main/truck.jpg"), # Or use image_file_to_base64("IMAGE_PATH")
"make_overlay": True,
"save_polygons": True,
"save_rle": True,
"save_pngs": True,
"points_per_side": 32,
"points_per_batch": 64,
"pred_iou_thresh": 0.86,
"stability_score_thresh": 0,
"min_mask_region_area": 0,
"nms_iou_thresh": 0.7,
"max_masks": 0,
"polygon_epsilon": 0,
"tile_size": 0,
"tile_stride": 0
}
headers = {'x-api-key': api_key}
response = requests.post(url, json=data, headers=headers)
print(response.content) # The response is the generated image
Attributes
Input image URL or base64 encoded image
Generate overlay image with masks
Include polygon coordinates in output
Include COCO RLE format in output
Generate individual PNG masks in ZIP
Number of points per side for mask generation
min : 8,
max : 64
Number of points per batch for processing
min : 16,
max : 128
Prediction IoU threshold for mask filtering
min : 0.5,
max : 1
Stability score threshold for mask filtering
min : 0,
max : 1
Minimum mask area in pixels
min : 0,
max : 10000
Non-Maximum Suppression IoU threshold
min : 0,
max : 1
Maximum number of masks to return (0 = no limit)
min : 0,
max : 100
Epsilon for polygon simplification
min : 0,
max : 10
Tile size for large images (0 = disabled)
min : 0,
max : 2048
Tile stride for large images (0 = use tile_size)
min : 0,
max : 2048
To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.
Resources to get you started
Everything you need to know to get the most out of Sam V2.1 Hiera Large
SAM v2.1 Hiera Large
SAM v2.1 (Segment Anything Model 2.1) represents the next evolution in promptable visual segmentation by Meta AI, delivering more accurate and efficient mask generation for a wide range of image types and contexts.
Model Information
- •Architecture: SAM v2.1 extends the original SAM framework with optimized Hiera-based encoders for higher accuracy and speed.
- •Flexible Outputs: Supports overlay images, polygon coordinates, COCO RLE encodings, and individual PNG masks.
How to Use the Model
- •Upload an image (JPG, PNG, or WebP) — either as a URL or base64 string.
- •Configure output options:
- •make_overlay – Generate a visual overlay of masks on the input image.
- •save_polygons – Return polygon coordinates for each segmented region.
- •save_rle – Export COCO RLE encodings for mask data.
- •save_pngs – Save individual masks as PNGs in a ZIP file.
- •Adjust advanced parameters for quality and precision:
- •points_per_side, points_per_batch, pred_iou_thresh, stability_score_thresh, min_mask_region_area, nms_iou_thresh, max_masks, polygon_epsilon, tile_size, tile_stride.
- •Click “Generate” to obtain segmentation results.
Use Cases
- •Assisted Image Labeling: Speeds up dataset annotation with automatic mask proposals.
- •AR/VR Applications: Enables precise object isolation for immersive environments.
- •Autonomous Vehicles: Supports accurate perception and obstacle detection.
- •Environmental Monitoring: Segments satellite and aerial imagery for analysis.
- •Industrial & Sonar Imaging: Identifies regions of interest in complex visual data.
Other Popular Models
Discover other models you might be interested in.
sdxl-img2img
SDXL Img2Img is used for text-guided image-to-image translation. This model uses the weights from Stable Diffusion to generate new images from an input image using StableDiffusionImg2ImgPipeline from diffusers

sdxl-inpaint
This model is capable of generating photo-realistic images given any text input, with the extra capability of inpainting the pictures by using a mask

codeformer
CodeFormer is a robust face restoration algorithm for old photos or AI-generated faces.

sd2.1-faceswapper
Take a picture/gif and replace the face in it with a face of your choice. You only need one image of the desired face. No dataset, no training
