Instructions to use zeromodels/sam_vit_huge with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/sam_vit_huge with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use zeromodels/sam_vit_huge with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/sam_vit_huge") - Notebooks
- Google Colab
- Kaggle
docs: Unsloth-style KerasFormers model card for sam_vit_huge
Browse files
README.md
CHANGED
|
@@ -1,21 +1,91 @@
|
|
| 1 |
---
|
| 2 |
pipeline_tag: mask-generation
|
| 3 |
license: apache-2.0
|
|
|
|
| 4 |
library_name: kerasformers
|
| 5 |
tags:
|
| 6 |
- keras
|
| 7 |
- kerasformers
|
| 8 |
- sam
|
| 9 |
-
-
|
| 10 |
-
-
|
|
|
|
| 11 |
- pytorch
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```python
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
pipeline_tag: mask-generation
|
| 3 |
license: apache-2.0
|
| 4 |
+
base_model: facebook/sam-vit-huge
|
| 5 |
library_name: kerasformers
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
- kerasformers
|
| 9 |
- sam
|
| 10 |
+
- mask-generation
|
| 11 |
+
- image-segmentation
|
| 12 |
+
- arxiv:2304.02643
|
| 13 |
- pytorch
|
| 14 |
+
- jax
|
| 15 |
+
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/kerasformers/sam-v1-v2-v3-6a6a8c261dabbc2996e1b4a2) for all versions of SAM.***
|
| 19 |
+
|
| 20 |
+
# Run SAM with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
+
|
| 22 |
+
[](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/sam/) [](https://huggingface.co/collections/kerasformers/sam-v1-v2-v3-6a6a8c261dabbc2996e1b4a2)
|
| 23 |
+
|
| 24 |
+
# kerasformers/sam_vit_huge
|
| 25 |
+
|
| 26 |
+
Paper: [Segment Anything (arXiv:2304.02643)](https://arxiv.org/abs/2304.02643) · [HF Papers](https://huggingface.co/papers/2304.02643)
|
| 27 |
+
|
| 28 |
+
SAM (Segment Anything Model) segments whatever you point at. It has no class vocabulary: you give it a prompt (a click or a box) and it returns a mask. A heavy ViT image encoder runs once per image; the prompt encoder and mask decoder are light enough for interactive use.
|
| 29 |
+
|
| 30 |
+
For more details on the model, please go to Meta's original [model card](https://huggingface.co/facebook/sam-vit-huge).
|
| 31 |
+
|
| 32 |
+
Pure-**Keras 3** conversion of [`facebook/sam-vit-huge`](https://huggingface.co/facebook/sam-vit-huge) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 33 |
|
| 34 |
+
This is a **promptable segmentation** checkpoint (`SAMPromptableSegment`): point (and optional box) prompts, backbone ViT-H.
|
| 35 |
+
|
| 36 |
+
## ✨ Quick start
|
| 37 |
|
| 38 |
```python
|
| 39 |
+
import os
|
| 40 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 41 |
+
|
| 42 |
+
import numpy as np
|
| 43 |
+
from PIL import Image
|
| 44 |
+
from kerasformers.models.sam import (
|
| 45 |
+
SAMPromptableSegment,
|
| 46 |
+
SAMImageProcessorWithPrompts,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
model = SAMPromptableSegment.from_weights("kerasformers/sam_vit_huge")
|
| 50 |
+
processor = SAMImageProcessorWithPrompts()
|
| 51 |
+
|
| 52 |
+
image = Image.open("your_image.jpg").convert("RGB")
|
| 53 |
+
inputs = processor(
|
| 54 |
+
image,
|
| 55 |
+
input_points=np.array([[[[450, 200]]]], dtype="float32"),
|
| 56 |
+
input_labels=np.array([[[1]]], dtype="int32"),
|
| 57 |
+
)
|
| 58 |
+
META = ("original_size", "reshaped_size")
|
| 59 |
+
output = model({k: v for k, v in inputs.items() if k not in META})
|
| 60 |
+
masks = processor.post_process_masks(
|
| 61 |
+
output["pred_masks"], original_size=inputs["original_size"]
|
| 62 |
+
)
|
| 63 |
+
print(output["iou_scores"].shape, masks.shape)
|
| 64 |
```
|
| 65 |
+
|
| 66 |
+
Load any SAM / SAM2 / SAM3 variant the same way with `from_weights("kerasformers/<variant>")` (use `SAMPromptableSegment` for this repo):
|
| 67 |
+
|
| 68 |
+
| Variant | Hub | Family |
|
| 69 |
+
|---|---|---|
|
| 70 |
+
| `sam_vit_base` | [`kerasformers/sam_vit_base`](https://huggingface.co/kerasformers/sam_vit_base) | SAM |
|
| 71 |
+
| `sam_vit_large` | [`kerasformers/sam_vit_large`](https://huggingface.co/kerasformers/sam_vit_large) | SAM |
|
| 72 |
+
| `sam_vit_huge` | [`kerasformers/sam_vit_huge`](https://huggingface.co/kerasformers/sam_vit_huge) | SAM |
|
| 73 |
+
| `sam2_hiera_small` | [`kerasformers/sam2_hiera_small`](https://huggingface.co/kerasformers/sam2_hiera_small) | SAM2 |
|
| 74 |
+
| `sam2_hiera_base_plus` | [`kerasformers/sam2_hiera_base_plus`](https://huggingface.co/kerasformers/sam2_hiera_base_plus) | SAM2 |
|
| 75 |
+
| `sam2_hiera_large` | [`kerasformers/sam2_hiera_large`](https://huggingface.co/kerasformers/sam2_hiera_large) | SAM2 |
|
| 76 |
+
| `sam3` | [`kerasformers/sam3`](https://huggingface.co/kerasformers/sam3) | SAM3 |
|
| 77 |
+
|
| 78 |
+
## Tips
|
| 79 |
+
|
| 80 |
+
- Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
|
| 81 |
+
- SAM / SAM2: point coordinates are in original pixel space; box prompts need `enable_boxes=True` / `include_box_input=True` when building the graph.
|
| 82 |
+
- SAM2 in this port is image-only (no video memory bank).
|
| 83 |
+
- SAM3: prefer `SAM3InstanceSegment.predict(...)` for text prompts; upstream `facebook/sam3` is gated.
|
| 84 |
+
- See [SAM docs](https://imvision12.github.io/KerasFormers/sam/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
|
| 85 |
+
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `SAMPromptableSegment.from_weights("hf:facebook/sam-vit-huge")`.
|
| 86 |
+
|
| 87 |
+
## Special Thanks
|
| 88 |
+
|
| 89 |
+
A huge thank you to the Meta Segment Anything authors for creating and releasing these models.
|
| 90 |
+
|
| 91 |
+
License: Apache 2.0.
|