Instructions to use zeromodels/sam2_hiera_tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/sam2_hiera_tiny 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/sam2_hiera_tiny") - sam2
How to use zeromodels/sam2_hiera_tiny with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained(zeromodels/sam2_hiera_tiny) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained(zeromodels/sam2_hiera_tiny) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>): # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +8 -5
- kf_config.json → zm_config.json +54 -54
- kf_preprocessor.json → zm_preprocessor.json +18 -18
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
pipeline_tag: mask-generation
|
| 3 |
license: apache-2.0
|
| 4 |
-
library_name:
|
| 5 |
tags:
|
| 6 |
- keras
|
| 7 |
-
-
|
| 8 |
- sam2
|
| 9 |
- tf
|
| 10 |
- jax
|
|
@@ -13,9 +13,12 @@ tags:
|
|
| 13 |
|
| 14 |
# sam2_hiera_tiny (Keras 3)
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```python
|
| 19 |
-
from
|
| 20 |
model = SAM2PromptableSegment.from_weights("sam2_hiera_tiny")
|
| 21 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
pipeline_tag: mask-generation
|
| 3 |
license: apache-2.0
|
| 4 |
+
library_name: zeromodels
|
| 5 |
tags:
|
| 6 |
- keras
|
| 7 |
+
- zeromodels
|
| 8 |
- sam2
|
| 9 |
- tf
|
| 10 |
- jax
|
|
|
|
| 13 |
|
| 14 |
# sam2_hiera_tiny (Keras 3)
|
| 15 |
|
| 16 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/sam2/) [](https://huggingface.co/collections/zeromodels/sam-v1-v2-v3-6a6a8c261dabbc2996e1b4a2)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Pure-Keras 3 weights for [zeromodels](https://github.com/IMvision12/ZeroModels), mirrored from the source. License: `apache-2.0`.
|
| 20 |
|
| 21 |
```python
|
| 22 |
+
from zeromodels.models.sam2 import SAM2PromptableSegment
|
| 23 |
model = SAM2PromptableSegment.from_weights("sam2_hiera_tiny")
|
| 24 |
+
```
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,55 +1,55 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "SAM2PromptableSegment",
|
| 6 |
-
"variant": "sam2_hiera_tiny",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "sam2",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"hidden_dim": 96,
|
| 13 |
-
"blocks_per_stage": [
|
| 14 |
-
1,
|
| 15 |
-
2,
|
| 16 |
-
7,
|
| 17 |
-
2
|
| 18 |
-
],
|
| 19 |
-
"embed_dim_per_stage": [
|
| 20 |
-
96,
|
| 21 |
-
192,
|
| 22 |
-
384,
|
| 23 |
-
768
|
| 24 |
-
],
|
| 25 |
-
"num_attention_heads_per_stage": [
|
| 26 |
-
1,
|
| 27 |
-
2,
|
| 28 |
-
4,
|
| 29 |
-
8
|
| 30 |
-
],
|
| 31 |
-
"window_size_per_stage": [
|
| 32 |
-
8,
|
| 33 |
-
4,
|
| 34 |
-
14,
|
| 35 |
-
7
|
| 36 |
-
],
|
| 37 |
-
"global_attention_blocks": [
|
| 38 |
-
5,
|
| 39 |
-
7,
|
| 40 |
-
9
|
| 41 |
-
],
|
| 42 |
-
"backbone_channel_list": [
|
| 43 |
-
768,
|
| 44 |
-
384,
|
| 45 |
-
192,
|
| 46 |
-
96
|
| 47 |
-
],
|
| 48 |
-
"window_pos_embed_bg_size": null,
|
| 49 |
-
"num_multimask_outputs": 3,
|
| 50 |
-
"include_box_input": false,
|
| 51 |
-
"include_mask_input": false,
|
| 52 |
-
"multimask_output": true,
|
| 53 |
-
"image_size": 1024
|
| 54 |
-
}
|
| 55 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.sam2",
|
| 5 |
+
"model_class": "SAM2PromptableSegment",
|
| 6 |
+
"variant": "sam2_hiera_tiny",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "sam2",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"hidden_dim": 96,
|
| 13 |
+
"blocks_per_stage": [
|
| 14 |
+
1,
|
| 15 |
+
2,
|
| 16 |
+
7,
|
| 17 |
+
2
|
| 18 |
+
],
|
| 19 |
+
"embed_dim_per_stage": [
|
| 20 |
+
96,
|
| 21 |
+
192,
|
| 22 |
+
384,
|
| 23 |
+
768
|
| 24 |
+
],
|
| 25 |
+
"num_attention_heads_per_stage": [
|
| 26 |
+
1,
|
| 27 |
+
2,
|
| 28 |
+
4,
|
| 29 |
+
8
|
| 30 |
+
],
|
| 31 |
+
"window_size_per_stage": [
|
| 32 |
+
8,
|
| 33 |
+
4,
|
| 34 |
+
14,
|
| 35 |
+
7
|
| 36 |
+
],
|
| 37 |
+
"global_attention_blocks": [
|
| 38 |
+
5,
|
| 39 |
+
7,
|
| 40 |
+
9
|
| 41 |
+
],
|
| 42 |
+
"backbone_channel_list": [
|
| 43 |
+
768,
|
| 44 |
+
384,
|
| 45 |
+
192,
|
| 46 |
+
96
|
| 47 |
+
],
|
| 48 |
+
"window_pos_embed_bg_size": null,
|
| 49 |
+
"num_multimask_outputs": 3,
|
| 50 |
+
"include_box_input": false,
|
| 51 |
+
"include_mask_input": false,
|
| 52 |
+
"multimask_output": true,
|
| 53 |
+
"image_size": 1024
|
| 54 |
+
}
|
| 55 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "SAM2ImageProcessor",
|
| 6 |
-
"variant": "sam2_hiera_tiny",
|
| 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.sam2",
|
| 5 |
+
"preprocessor_class": "SAM2ImageProcessor",
|
| 6 |
+
"variant": "sam2_hiera_tiny",
|
| 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 |
}
|