Views
No views yet
facebook/sam-vit-huge for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.SAMPromptableSegment): point (and optional box) prompts, backbone ViT-H.1import os
2os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
3
4import numpy as np
5from PIL import Image
6from zeromodels.models.sam import (
7 SAMPromptableSegment,
8 SAMProcessor,
9)
10
11model = SAMPromptableSegment.from_weights("zeromodels/sam_vit_huge")
12processor = SAMProcessor.from_weights("zeromodels/sam_vit_huge")
13
14image = Image.open("your_image.jpg").convert("RGB")
15inputs = processor(
16 image,
17 input_points=np.array([[[[450, 200]]]], dtype="float32"),
18 input_labels=np.array([[[1]]], dtype="int32"),
19)
20META = ("original_size", "reshaped_size")
21output = model({k: v for k, v in inputs.items() if k not in META})
22masks = processor.post_process_masks(
23 output["pred_masks"], original_size=inputs["original_size"]
24)
25print(output["iou_scores"].shape, masks.shape)from_weights("zeromodels/<variant>") (use SAMPromptableSegment for this repo):| Variant | Hub | Family |
|---|---|---|
sam_vit_base | zeromodels/sam_vit_base | SAM |
sam_vit_large | zeromodels/sam_vit_large | SAM |
sam_vit_huge | zeromodels/sam_vit_huge | SAM |
sam2_hiera_small | zeromodels/sam2_hiera_small | SAM2 |
sam2_hiera_base_plus | zeromodels/sam2_hiera_base_plus | SAM2 |
sam2_hiera_large | zeromodels/sam2_hiera_large | SAM2 |
sam3 | zeromodels/sam3 | SAM3 |
KERAS_BACKEND before importing Keras / zeromodels.enable_boxes=True / include_box_input=True when building the graph.SAM3InstanceSegment.predict(...) for text prompts; upstream facebook/sam3 is gated.hf: prefix, e.g. SAMPromptableSegment.from_weights("hf:facebook/sam-vit-huge").