Instructions to use zeromodels/mit_b1_in1k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/mit_b1_in1k 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/mit_b1_in1k") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +18 -18
- kf_config.json → zm_config.json +26 -26
README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
pipeline_tag: image-classification
|
| 3 |
license: other
|
| 4 |
base_model: nvidia/mit-b1
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
-
-
|
| 9 |
- image-classification
|
| 10 |
- mit
|
| 11 |
- backbone
|
|
@@ -15,13 +15,13 @@ tags:
|
|
| 15 |
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 19 |
|
| 20 |
# Run MiT with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
|
| 22 |
-
[](https://arxiv.org/abs/2105.15203) · [HF Papers](https://huggingface.co/papers/2105.15203)
|
| 27 |
|
|
@@ -29,7 +29,7 @@ MiT is the hierarchical Mix Transformer encoder from SegFormer, also usable for
|
|
| 29 |
|
| 30 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/nvidia/mit-b1).
|
| 31 |
|
| 32 |
-
Pure-**Keras 3** conversion of [`nvidia/mit-b1`](https://huggingface.co/nvidia/mit-b1) for [
|
| 33 |
|
| 34 |
This is an **image-classification / backbone** checkpoint (`MiTImageClassify` / `MiTModel`).
|
| 35 |
|
|
@@ -41,11 +41,11 @@ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
|
| 41 |
|
| 42 |
from PIL import Image
|
| 43 |
import numpy as np
|
| 44 |
-
from
|
| 45 |
|
| 46 |
-
model = MiTImageClassify.from_weights("
|
| 47 |
backbone = MiTModel.from_weights(
|
| 48 |
-
"
|
| 49 |
)
|
| 50 |
|
| 51 |
image = Image.open("your_image.jpg").convert("RGB")
|
|
@@ -56,22 +56,22 @@ feats = backbone(x)
|
|
| 56 |
print(len(feats), [tuple(f.shape) for f in feats])
|
| 57 |
```
|
| 58 |
|
| 59 |
-
Load any MiT variant the same way with `from_weights("
|
| 60 |
|
| 61 |
| Variant | Hub |
|
| 62 |
|---|---|
|
| 63 |
-
| `mit_b0_in1k` | [`
|
| 64 |
-
| `mit_b1_in1k` | [`
|
| 65 |
-
| `mit_b2_in1k` | [`
|
| 66 |
-
| `mit_b3_in1k` | [`
|
| 67 |
-
| `mit_b4_in1k` | [`
|
| 68 |
-
| `mit_b5_in1k` | [`
|
| 69 |
|
| 70 |
## Tips
|
| 71 |
|
| 72 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 73 |
- `MiTImageClassify` returns class logits; `MiTModel` returns features (`as_backbone=True` for multi-scale stages).
|
| 74 |
-
- See [docs](https://imvision12.github.io/
|
| 75 |
- Upstream / timm checkpoints: `MiTImageClassify.from_weights("hf:nvidia/mit-b1")`.
|
| 76 |
|
| 77 |
## Special Thanks
|
|
|
|
| 2 |
pipeline_tag: image-classification
|
| 3 |
license: other
|
| 4 |
base_model: nvidia/mit-b1
|
| 5 |
+
library_name: zeromodels
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
- image-classification
|
| 10 |
- mit
|
| 11 |
- backbone
|
|
|
|
| 15 |
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/mit-segformer-encoder-6a6e81367fda42bf79b426e8) for all versions of MiT.***
|
| 19 |
|
| 20 |
# Run MiT with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
|
| 22 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/classification_backbones/) [](https://huggingface.co/collections/zeromodels/mit-segformer-encoder-6a6e81367fda42bf79b426e8)
|
| 23 |
|
| 24 |
+
# zeromodels/mit_b1_in1k
|
| 25 |
|
| 26 |
Paper: [SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers (arXiv:2105.15203)](https://arxiv.org/abs/2105.15203) · [HF Papers](https://huggingface.co/papers/2105.15203)
|
| 27 |
|
|
|
|
| 29 |
|
| 30 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/nvidia/mit-b1).
|
| 31 |
|
| 32 |
+
Pure-**Keras 3** conversion of [`nvidia/mit-b1`](https://huggingface.co/nvidia/mit-b1) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 33 |
|
| 34 |
This is an **image-classification / backbone** checkpoint (`MiTImageClassify` / `MiTModel`).
|
| 35 |
|
|
|
|
| 41 |
|
| 42 |
from PIL import Image
|
| 43 |
import numpy as np
|
| 44 |
+
from zeromodels.models.mit import MiTImageClassify, MiTModel
|
| 45 |
|
| 46 |
+
model = MiTImageClassify.from_weights("zeromodels/mit_b1_in1k")
|
| 47 |
backbone = MiTModel.from_weights(
|
| 48 |
+
"zeromodels/mit_b1_in1k", as_backbone=True
|
| 49 |
)
|
| 50 |
|
| 51 |
image = Image.open("your_image.jpg").convert("RGB")
|
|
|
|
| 56 |
print(len(feats), [tuple(f.shape) for f in feats])
|
| 57 |
```
|
| 58 |
|
| 59 |
+
Load any MiT variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 60 |
|
| 61 |
| Variant | Hub |
|
| 62 |
|---|---|
|
| 63 |
+
| `mit_b0_in1k` | [`zeromodels/mit_b0_in1k`](https://huggingface.co/zeromodels/mit_b0_in1k) |
|
| 64 |
+
| `mit_b1_in1k` | [`zeromodels/mit_b1_in1k`](https://huggingface.co/zeromodels/mit_b1_in1k) |
|
| 65 |
+
| `mit_b2_in1k` | [`zeromodels/mit_b2_in1k`](https://huggingface.co/zeromodels/mit_b2_in1k) |
|
| 66 |
+
| `mit_b3_in1k` | [`zeromodels/mit_b3_in1k`](https://huggingface.co/zeromodels/mit_b3_in1k) |
|
| 67 |
+
| `mit_b4_in1k` | [`zeromodels/mit_b4_in1k`](https://huggingface.co/zeromodels/mit_b4_in1k) |
|
| 68 |
+
| `mit_b5_in1k` | [`zeromodels/mit_b5_in1k`](https://huggingface.co/zeromodels/mit_b5_in1k) |
|
| 69 |
|
| 70 |
## Tips
|
| 71 |
|
| 72 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 73 |
- `MiTImageClassify` returns class logits; `MiTModel` returns features (`as_backbone=True` for multi-scale stages).
|
| 74 |
+
- See [docs](https://imvision12.github.io/ZeroModels/classification_backbones/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 75 |
- Upstream / timm checkpoints: `MiTImageClassify.from_weights("hf:nvidia/mit-b1")`.
|
| 76 |
|
| 77 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,27 +1,27 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "MiTImageClassify",
|
| 6 |
-
"variant": "mit_b1_in1k",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "mit",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"embed_dim": [
|
| 13 |
-
64,
|
| 14 |
-
128,
|
| 15 |
-
320,
|
| 16 |
-
512
|
| 17 |
-
],
|
| 18 |
-
"depths": [
|
| 19 |
-
2,
|
| 20 |
-
2,
|
| 21 |
-
2,
|
| 22 |
-
2
|
| 23 |
-
],
|
| 24 |
-
"image_size": 224,
|
| 25 |
-
"num_classes": 1000
|
| 26 |
-
}
|
| 27 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.mit",
|
| 5 |
+
"model_class": "MiTImageClassify",
|
| 6 |
+
"variant": "mit_b1_in1k",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "mit",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"embed_dim": [
|
| 13 |
+
64,
|
| 14 |
+
128,
|
| 15 |
+
320,
|
| 16 |
+
512
|
| 17 |
+
],
|
| 18 |
+
"depths": [
|
| 19 |
+
2,
|
| 20 |
+
2,
|
| 21 |
+
2,
|
| 22 |
+
2
|
| 23 |
+
],
|
| 24 |
+
"image_size": 224,
|
| 25 |
+
"num_classes": 1000
|
| 26 |
+
}
|
| 27 |
}
|