Instructions to use zeromodels/sam_vit_large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/sam_vit_large 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_large") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +19 -19
- kf_config.json → zm_config.json +27 -27
- kf_preprocessor.json → zm_preprocessor.json +18 -18
README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
pipeline_tag: mask-generation
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: facebook/sam-vit-large
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
-
-
|
| 9 |
- sam
|
| 10 |
- mask-generation
|
| 11 |
- image-segmentation
|
|
@@ -15,13 +15,13 @@ tags:
|
|
| 15 |
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 19 |
|
| 20 |
# Run SAM with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
|
| 22 |
-
[](https://arxiv.org/abs/2304.02643) · [HF Papers](https://huggingface.co/papers/2304.02643)
|
| 27 |
|
|
@@ -29,7 +29,7 @@ SAM (Segment Anything Model) segments whatever you point at. It has no class voc
|
|
| 29 |
|
| 30 |
For more details on the model, please go to Meta's original [model card](https://huggingface.co/facebook/sam-vit-large).
|
| 31 |
|
| 32 |
-
Pure-**Keras 3** conversion of [`facebook/sam-vit-large`](https://huggingface.co/facebook/sam-vit-large) for [
|
| 33 |
|
| 34 |
This is a **promptable segmentation** checkpoint (`SAMPromptableSegment`): point (and optional box) prompts, backbone ViT-L.
|
| 35 |
|
|
@@ -41,13 +41,13 @@ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
|
| 41 |
|
| 42 |
import numpy as np
|
| 43 |
from PIL import Image
|
| 44 |
-
from
|
| 45 |
SAMPromptableSegment,
|
| 46 |
SAMProcessor,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
model = SAMPromptableSegment.from_weights("
|
| 50 |
-
processor = SAMProcessor.from_weights("
|
| 51 |
|
| 52 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 53 |
inputs = processor(
|
|
@@ -63,25 +63,25 @@ masks = processor.post_process_masks(
|
|
| 63 |
print(output["iou_scores"].shape, masks.shape)
|
| 64 |
```
|
| 65 |
|
| 66 |
-
Load any SAM / SAM2 / SAM3 variant the same way with `from_weights("
|
| 67 |
|
| 68 |
| Variant | Hub | Family |
|
| 69 |
|---|---|---|
|
| 70 |
-
| `sam_vit_base` | [`
|
| 71 |
-
| `sam_vit_large` | [`
|
| 72 |
-
| `sam_vit_huge` | [`
|
| 73 |
-
| `sam2_hiera_small` | [`
|
| 74 |
-
| `sam2_hiera_base_plus` | [`
|
| 75 |
-
| `sam2_hiera_large` | [`
|
| 76 |
-
| `sam3` | [`
|
| 77 |
|
| 78 |
## Tips
|
| 79 |
|
| 80 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 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/
|
| 85 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `SAMPromptableSegment.from_weights("hf:facebook/sam-vit-large")`.
|
| 86 |
|
| 87 |
## Special Thanks
|
|
|
|
| 2 |
pipeline_tag: mask-generation
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: facebook/sam-vit-large
|
| 5 |
+
library_name: zeromodels
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
- sam
|
| 10 |
- mask-generation
|
| 11 |
- image-segmentation
|
|
|
|
| 15 |
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/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/ZeroModels) [](https://imvision12.github.io/ZeroModels/sam/) [](https://huggingface.co/collections/zeromodels/sam-v1-v2-v3-6a6a8c261dabbc2996e1b4a2)
|
| 23 |
|
| 24 |
+
# zeromodels/sam_vit_large
|
| 25 |
|
| 26 |
Paper: [Segment Anything (arXiv:2304.02643)](https://arxiv.org/abs/2304.02643) · [HF Papers](https://huggingface.co/papers/2304.02643)
|
| 27 |
|
|
|
|
| 29 |
|
| 30 |
For more details on the model, please go to Meta's original [model card](https://huggingface.co/facebook/sam-vit-large).
|
| 31 |
|
| 32 |
+
Pure-**Keras 3** conversion of [`facebook/sam-vit-large`](https://huggingface.co/facebook/sam-vit-large) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 33 |
|
| 34 |
This is a **promptable segmentation** checkpoint (`SAMPromptableSegment`): point (and optional box) prompts, backbone ViT-L.
|
| 35 |
|
|
|
|
| 41 |
|
| 42 |
import numpy as np
|
| 43 |
from PIL import Image
|
| 44 |
+
from zeromodels.models.sam import (
|
| 45 |
SAMPromptableSegment,
|
| 46 |
SAMProcessor,
|
| 47 |
)
|
| 48 |
|
| 49 |
+
model = SAMPromptableSegment.from_weights("zeromodels/sam_vit_large")
|
| 50 |
+
processor = SAMProcessor.from_weights("zeromodels/sam_vit_large")
|
| 51 |
|
| 52 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 53 |
inputs = processor(
|
|
|
|
| 63 |
print(output["iou_scores"].shape, masks.shape)
|
| 64 |
```
|
| 65 |
|
| 66 |
+
Load any SAM / SAM2 / SAM3 variant the same way with `from_weights("zeromodels/<variant>")` (use `SAMPromptableSegment` for this repo):
|
| 67 |
|
| 68 |
| Variant | Hub | Family |
|
| 69 |
|---|---|---|
|
| 70 |
+
| `sam_vit_base` | [`zeromodels/sam_vit_base`](https://huggingface.co/zeromodels/sam_vit_base) | SAM |
|
| 71 |
+
| `sam_vit_large` | [`zeromodels/sam_vit_large`](https://huggingface.co/zeromodels/sam_vit_large) | SAM |
|
| 72 |
+
| `sam_vit_huge` | [`zeromodels/sam_vit_huge`](https://huggingface.co/zeromodels/sam_vit_huge) | SAM |
|
| 73 |
+
| `sam2_hiera_small` | [`zeromodels/sam2_hiera_small`](https://huggingface.co/zeromodels/sam2_hiera_small) | SAM2 |
|
| 74 |
+
| `sam2_hiera_base_plus` | [`zeromodels/sam2_hiera_base_plus`](https://huggingface.co/zeromodels/sam2_hiera_base_plus) | SAM2 |
|
| 75 |
+
| `sam2_hiera_large` | [`zeromodels/sam2_hiera_large`](https://huggingface.co/zeromodels/sam2_hiera_large) | SAM2 |
|
| 76 |
+
| `sam3` | [`zeromodels/sam3`](https://huggingface.co/zeromodels/sam3) | SAM3 |
|
| 77 |
|
| 78 |
## Tips
|
| 79 |
|
| 80 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 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/ZeroModels/sam/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 85 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `SAMPromptableSegment.from_weights("hf:facebook/sam-vit-large")`.
|
| 86 |
|
| 87 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "SAMPromptableSegment",
|
| 6 |
-
"variant": "sam_vit_large",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "sam",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"vision_hidden_size": 1024,
|
| 13 |
-
"vision_num_hidden_layers": 24,
|
| 14 |
-
"vision_num_attention_heads": 16,
|
| 15 |
-
"vision_mlp_dim": 4096,
|
| 16 |
-
"vision_global_attn_indexes": [
|
| 17 |
-
5,
|
| 18 |
-
11,
|
| 19 |
-
17,
|
| 20 |
-
23
|
| 21 |
-
],
|
| 22 |
-
"num_multimask_outputs": 3,
|
| 23 |
-
"multimask_output": true,
|
| 24 |
-
"enable_boxes": false,
|
| 25 |
-
"enable_masks": false,
|
| 26 |
-
"image_size": 1024
|
| 27 |
-
}
|
| 28 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.sam",
|
| 5 |
+
"model_class": "SAMPromptableSegment",
|
| 6 |
+
"variant": "sam_vit_large",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "sam",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"vision_hidden_size": 1024,
|
| 13 |
+
"vision_num_hidden_layers": 24,
|
| 14 |
+
"vision_num_attention_heads": 16,
|
| 15 |
+
"vision_mlp_dim": 4096,
|
| 16 |
+
"vision_global_attn_indexes": [
|
| 17 |
+
5,
|
| 18 |
+
11,
|
| 19 |
+
17,
|
| 20 |
+
23
|
| 21 |
+
],
|
| 22 |
+
"num_multimask_outputs": 3,
|
| 23 |
+
"multimask_output": true,
|
| 24 |
+
"enable_boxes": false,
|
| 25 |
+
"enable_masks": false,
|
| 26 |
+
"image_size": 1024
|
| 27 |
+
}
|
| 28 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "SAMImageProcessor",
|
| 6 |
-
"variant": "sam_vit_large",
|
| 7 |
-
"target_length": 1024,
|
| 8 |
-
"image_mean": [
|
| 9 |
-
0.485,
|
| 10 |
-
0.456,
|
| 11 |
-
0.406
|
| 12 |
-
],
|
| 13 |
-
"image_std": [
|
| 14 |
-
0.229,
|
| 15 |
-
0.224,
|
| 16 |
-
0.225
|
| 17 |
-
],
|
| 18 |
-
"data_format": null
|
| 19 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.1.3",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.sam",
|
| 5 |
+
"preprocessor_class": "SAMImageProcessor",
|
| 6 |
+
"variant": "sam_vit_large",
|
| 7 |
+
"target_length": 1024,
|
| 8 |
+
"image_mean": [
|
| 9 |
+
0.485,
|
| 10 |
+
0.456,
|
| 11 |
+
0.406
|
| 12 |
+
],
|
| 13 |
+
"image_std": [
|
| 14 |
+
0.229,
|
| 15 |
+
0.224,
|
| 16 |
+
0.225
|
| 17 |
+
],
|
| 18 |
+
"data_format": null
|
| 19 |
}
|