Instructions to use zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k") - Keras
How to use zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_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/swin_base_patch4_window12_384_ms_in22k_ft_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 +27 -27
- kf_config.json → zm_config.json +29 -29
README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
pipeline_tag: image-classification
|
| 3 |
license: mit
|
| 4 |
base_model: timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
-
-
|
| 9 |
- image-classification
|
| 10 |
- swin
|
| 11 |
- backbone
|
|
@@ -15,13 +15,13 @@ tags:
|
|
| 15 |
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 19 |
|
| 20 |
# Run Swin Transformer with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
|
| 22 |
-
[](https://arxiv.org/abs/2103.14030) · [HF Papers](https://huggingface.co/papers/2103.14030)
|
| 27 |
|
|
@@ -29,7 +29,7 @@ Swin Transformer builds hierarchical feature maps with shifted-window attention.
|
|
| 29 |
|
| 30 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k).
|
| 31 |
|
| 32 |
-
Pure-**Keras 3** conversion of [`timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k`](https://huggingface.co/timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k) for [
|
| 33 |
|
| 34 |
This is an **image-classification / backbone** checkpoint (`SwinImageClassify` / `SwinModel`).
|
| 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 = SwinImageClassify.from_weights("
|
| 47 |
backbone = SwinModel.from_weights(
|
| 48 |
-
"
|
| 49 |
)
|
| 50 |
|
| 51 |
image = Image.open("your_image.jpg").convert("RGB")
|
|
@@ -56,31 +56,31 @@ feats = backbone(x)
|
|
| 56 |
print(len(feats), [tuple(f.shape) for f in feats])
|
| 57 |
```
|
| 58 |
|
| 59 |
-
Load any Swin Transformer variant the same way with `from_weights("
|
| 60 |
|
| 61 |
| Variant | Hub |
|
| 62 |
|---|---|
|
| 63 |
-
| `swin_base_patch4_window12_384_ms_in1k` | [`
|
| 64 |
-
| `swin_base_patch4_window12_384_ms_in22k` | [`
|
| 65 |
-
| `swin_base_patch4_window12_384_ms_in22k_ft_in1k` | [`
|
| 66 |
-
| `swin_base_patch4_window7_224_ms_in1k` | [`
|
| 67 |
-
| `swin_base_patch4_window7_224_ms_in22k` | [`
|
| 68 |
-
| `swin_base_patch4_window7_224_ms_in22k_ft_in1k` | [`
|
| 69 |
-
| `swin_large_patch4_window12_384_ms_in22k` | [`
|
| 70 |
-
| `swin_large_patch4_window12_384_ms_in22k_ft_in1k` | [`
|
| 71 |
-
| `swin_large_patch4_window7_224_ms_in22k` | [`
|
| 72 |
-
| `swin_large_patch4_window7_224_ms_in22k_ft_in1k` | [`
|
| 73 |
-
| `swin_small_patch4_window7_224_ms_in1k` | [`
|
| 74 |
-
| `swin_small_patch4_window7_224_ms_in22k` | [`
|
| 75 |
-
| `swin_small_patch4_window7_224_ms_in22k_ft_in1k` | [`
|
| 76 |
-
| `swin_tiny_patch4_window7_224_ms_in1k` | [`
|
| 77 |
-
| `swin_tiny_patch4_window7_224_ms_in22k` | [`
|
| 78 |
|
| 79 |
## Tips
|
| 80 |
|
| 81 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 82 |
- `SwinImageClassify` returns class logits; `SwinModel` returns features (`as_backbone=True` for multi-scale stages).
|
| 83 |
-
- See [docs](https://imvision12.github.io/
|
| 84 |
- Upstream / timm checkpoints: `SwinImageClassify.from_weights("hf:timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k")`.
|
| 85 |
|
| 86 |
## Special Thanks
|
|
|
|
| 2 |
pipeline_tag: image-classification
|
| 3 |
license: mit
|
| 4 |
base_model: timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k
|
| 5 |
+
library_name: zeromodels
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
- image-classification
|
| 10 |
- swin
|
| 11 |
- backbone
|
|
|
|
| 15 |
- tf
|
| 16 |
---
|
| 17 |
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/swin-transformer-6a6c7c6d86b6537929511843) for all versions of Swin Transformer.***
|
| 19 |
|
| 20 |
# Run Swin Transformer 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/swin-transformer-6a6c7c6d86b6537929511843)
|
| 23 |
|
| 24 |
+
# zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k
|
| 25 |
|
| 26 |
Paper: [Swin Transformer: Hierarchical Vision Transformer using Shifted Windows (arXiv:2103.14030)](https://arxiv.org/abs/2103.14030) · [HF Papers](https://huggingface.co/papers/2103.14030)
|
| 27 |
|
|
|
|
| 29 |
|
| 30 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k).
|
| 31 |
|
| 32 |
+
Pure-**Keras 3** conversion of [`timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k`](https://huggingface.co/timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 33 |
|
| 34 |
This is an **image-classification / backbone** checkpoint (`SwinImageClassify` / `SwinModel`).
|
| 35 |
|
|
|
|
| 41 |
|
| 42 |
from PIL import Image
|
| 43 |
import numpy as np
|
| 44 |
+
from zeromodels.models.swin import SwinImageClassify, SwinModel
|
| 45 |
|
| 46 |
+
model = SwinImageClassify.from_weights("zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k")
|
| 47 |
backbone = SwinModel.from_weights(
|
| 48 |
+
"zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_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 Swin Transformer variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 60 |
|
| 61 |
| Variant | Hub |
|
| 62 |
|---|---|
|
| 63 |
+
| `swin_base_patch4_window12_384_ms_in1k` | [`zeromodels/swin_base_patch4_window12_384_ms_in1k`](https://huggingface.co/zeromodels/swin_base_patch4_window12_384_ms_in1k) |
|
| 64 |
+
| `swin_base_patch4_window12_384_ms_in22k` | [`zeromodels/swin_base_patch4_window12_384_ms_in22k`](https://huggingface.co/zeromodels/swin_base_patch4_window12_384_ms_in22k) |
|
| 65 |
+
| `swin_base_patch4_window12_384_ms_in22k_ft_in1k` | [`zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k`](https://huggingface.co/zeromodels/swin_base_patch4_window12_384_ms_in22k_ft_in1k) |
|
| 66 |
+
| `swin_base_patch4_window7_224_ms_in1k` | [`zeromodels/swin_base_patch4_window7_224_ms_in1k`](https://huggingface.co/zeromodels/swin_base_patch4_window7_224_ms_in1k) |
|
| 67 |
+
| `swin_base_patch4_window7_224_ms_in22k` | [`zeromodels/swin_base_patch4_window7_224_ms_in22k`](https://huggingface.co/zeromodels/swin_base_patch4_window7_224_ms_in22k) |
|
| 68 |
+
| `swin_base_patch4_window7_224_ms_in22k_ft_in1k` | [`zeromodels/swin_base_patch4_window7_224_ms_in22k_ft_in1k`](https://huggingface.co/zeromodels/swin_base_patch4_window7_224_ms_in22k_ft_in1k) |
|
| 69 |
+
| `swin_large_patch4_window12_384_ms_in22k` | [`zeromodels/swin_large_patch4_window12_384_ms_in22k`](https://huggingface.co/zeromodels/swin_large_patch4_window12_384_ms_in22k) |
|
| 70 |
+
| `swin_large_patch4_window12_384_ms_in22k_ft_in1k` | [`zeromodels/swin_large_patch4_window12_384_ms_in22k_ft_in1k`](https://huggingface.co/zeromodels/swin_large_patch4_window12_384_ms_in22k_ft_in1k) |
|
| 71 |
+
| `swin_large_patch4_window7_224_ms_in22k` | [`zeromodels/swin_large_patch4_window7_224_ms_in22k`](https://huggingface.co/zeromodels/swin_large_patch4_window7_224_ms_in22k) |
|
| 72 |
+
| `swin_large_patch4_window7_224_ms_in22k_ft_in1k` | [`zeromodels/swin_large_patch4_window7_224_ms_in22k_ft_in1k`](https://huggingface.co/zeromodels/swin_large_patch4_window7_224_ms_in22k_ft_in1k) |
|
| 73 |
+
| `swin_small_patch4_window7_224_ms_in1k` | [`zeromodels/swin_small_patch4_window7_224_ms_in1k`](https://huggingface.co/zeromodels/swin_small_patch4_window7_224_ms_in1k) |
|
| 74 |
+
| `swin_small_patch4_window7_224_ms_in22k` | [`zeromodels/swin_small_patch4_window7_224_ms_in22k`](https://huggingface.co/zeromodels/swin_small_patch4_window7_224_ms_in22k) |
|
| 75 |
+
| `swin_small_patch4_window7_224_ms_in22k_ft_in1k` | [`zeromodels/swin_small_patch4_window7_224_ms_in22k_ft_in1k`](https://huggingface.co/zeromodels/swin_small_patch4_window7_224_ms_in22k_ft_in1k) |
|
| 76 |
+
| `swin_tiny_patch4_window7_224_ms_in1k` | [`zeromodels/swin_tiny_patch4_window7_224_ms_in1k`](https://huggingface.co/zeromodels/swin_tiny_patch4_window7_224_ms_in1k) |
|
| 77 |
+
| `swin_tiny_patch4_window7_224_ms_in22k` | [`zeromodels/swin_tiny_patch4_window7_224_ms_in22k`](https://huggingface.co/zeromodels/swin_tiny_patch4_window7_224_ms_in22k) |
|
| 78 |
|
| 79 |
## Tips
|
| 80 |
|
| 81 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 82 |
- `SwinImageClassify` returns class logits; `SwinModel` returns features (`as_backbone=True` for multi-scale stages).
|
| 83 |
+
- See [docs](https://imvision12.github.io/ZeroModels/classification_backbones/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 84 |
- Upstream / timm checkpoints: `SwinImageClassify.from_weights("hf:timm/swin_base_patch4_window12_384.ms_in22k_ft_in1k")`.
|
| 85 |
|
| 86 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,30 +1,30 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "SwinImageClassify",
|
| 6 |
-
"variant": "swin_base_patch4_window12_384_ms_in22k_ft_in1k",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "swin",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"window_size": 12,
|
| 13 |
-
"embed_dim": 128,
|
| 14 |
-
"depths": [
|
| 15 |
-
2,
|
| 16 |
-
2,
|
| 17 |
-
18,
|
| 18 |
-
2
|
| 19 |
-
],
|
| 20 |
-
"num_heads": [
|
| 21 |
-
4,
|
| 22 |
-
8,
|
| 23 |
-
16,
|
| 24 |
-
32
|
| 25 |
-
],
|
| 26 |
-
"pretrain_size": 384,
|
| 27 |
-
"image_size": 384,
|
| 28 |
-
"num_classes": 1000
|
| 29 |
-
}
|
| 30 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.swin",
|
| 5 |
+
"model_class": "SwinImageClassify",
|
| 6 |
+
"variant": "swin_base_patch4_window12_384_ms_in22k_ft_in1k",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "swin",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"window_size": 12,
|
| 13 |
+
"embed_dim": 128,
|
| 14 |
+
"depths": [
|
| 15 |
+
2,
|
| 16 |
+
2,
|
| 17 |
+
18,
|
| 18 |
+
2
|
| 19 |
+
],
|
| 20 |
+
"num_heads": [
|
| 21 |
+
4,
|
| 22 |
+
8,
|
| 23 |
+
16,
|
| 24 |
+
32
|
| 25 |
+
],
|
| 26 |
+
"pretrain_size": 384,
|
| 27 |
+
"image_size": 384,
|
| 28 |
+
"num_classes": 1000
|
| 29 |
+
}
|
| 30 |
}
|