Image Segmentation
ZeroModels
Keras
PyTorch
JAX
TensorFlow
segformer
semantic-segmentation
cityscapes
Instructions to use zeromodels/segformer_b5_cityscapes_1024 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/segformer_b5_cityscapes_1024 with ZeroModels:
# 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/segformer_b5_cityscapes_1024 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/segformer_b5_cityscapes_1024") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +25 -25
- kf_config.json → zm_config.json +28 -28
- kf_preprocessor.json → zm_preprocessor.json +27 -27
README.md
CHANGED
|
@@ -3,10 +3,10 @@ pipeline_tag: image-segmentation
|
|
| 3 |
license: other
|
| 4 |
license_link: https://github.com/NVlabs/SegFormer/blob/master/LICENSE
|
| 5 |
base_model: nvidia/segformer-b5-finetuned-cityscapes-1024-1024
|
| 6 |
-
library_name:
|
| 7 |
tags:
|
| 8 |
- keras
|
| 9 |
-
-
|
| 10 |
- segformer
|
| 11 |
- semantic-segmentation
|
| 12 |
- image-segmentation
|
|
@@ -17,13 +17,13 @@ tags:
|
|
| 17 |
- tf
|
| 18 |
---
|
| 19 |
|
| 20 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 21 |
|
| 22 |
# Run SegFormer with Keras 3: JAX, PyTorch, or TensorFlow
|
| 23 |
|
| 24 |
-
[](https://arxiv.org/abs/2105.15203) · [HF Papers](https://huggingface.co/papers/2105.15203)
|
| 29 |
|
|
@@ -31,7 +31,7 @@ SegFormer pairs a hierarchical transformer encoder (MiT) with a lightweight all-
|
|
| 31 |
|
| 32 |
For more details on the model, please go to NVIDIA's original [model card](https://huggingface.co/nvidia/segformer-b5-finetuned-cityscapes-1024-1024).
|
| 33 |
|
| 34 |
-
Pure-**Keras 3** conversion of [`nvidia/segformer-b5-finetuned-cityscapes-1024-1024`](https://huggingface.co/nvidia/segformer-b5-finetuned-cityscapes-1024-1024) for [
|
| 35 |
|
| 36 |
This is a **semantic segmentation** checkpoint (`SegFormerSemanticSegment`) for **Cityscapes** (19 classes, MiT-B5, 1024px).
|
| 37 |
|
|
@@ -42,13 +42,13 @@ import os
|
|
| 42 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 43 |
|
| 44 |
from PIL import Image
|
| 45 |
-
from
|
| 46 |
SegFormerSemanticSegment,
|
| 47 |
SegFormerImageProcessor,
|
| 48 |
)
|
| 49 |
|
| 50 |
-
model = SegFormerSemanticSegment.from_weights("
|
| 51 |
-
processor = SegFormerImageProcessor.from_weights("
|
| 52 |
|
| 53 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 54 |
output = model(processor(image)["pixel_values"], training=False)
|
|
@@ -58,29 +58,29 @@ result = processor.post_process_semantic_segmentation(
|
|
| 58 |
print(result["unique_classes"], result["class_names"])
|
| 59 |
```
|
| 60 |
|
| 61 |
-
Load any SegFormer variant the same way with `from_weights("
|
| 62 |
|
| 63 |
| Variant | Hub | Dataset | Res |
|
| 64 |
|---|---|---|---|
|
| 65 |
-
| `segformer_b0_ade_512` | [`
|
| 66 |
-
| `segformer_b1_ade_512` | [`
|
| 67 |
-
| `segformer_b2_ade_512` | [`
|
| 68 |
-
| `segformer_b3_ade_512` | [`
|
| 69 |
-
| `segformer_b4_ade_512` | [`
|
| 70 |
-
| `segformer_b5_ade_640` | [`
|
| 71 |
-
| `segformer_b0_cityscapes_768` | [`
|
| 72 |
-
| `segformer_b0_cityscapes_1024` | [`
|
| 73 |
-
| `segformer_b1_cityscapes_1024` | [`
|
| 74 |
-
| `segformer_b2_cityscapes_1024` | [`
|
| 75 |
-
| `segformer_b3_cityscapes_1024` | [`
|
| 76 |
-
| `segformer_b4_cityscapes_1024` | [`
|
| 77 |
-
| `segformer_b5_cityscapes_1024` | [`
|
| 78 |
|
| 79 |
## Tips
|
| 80 |
|
| 81 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 82 |
- Prefer `SegFormerImageProcessor.from_weights(...)` so the resize matches the variant (ADE B5 is 640; Cityscapes is often 1024).
|
| 83 |
-
- See [SegFormer docs](https://imvision12.github.io/
|
| 84 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `SegFormerSemanticSegment.from_weights("hf:nvidia/segformer-b5-finetuned-cityscapes-1024-1024")`.
|
| 85 |
|
| 86 |
## Special Thanks
|
|
|
|
| 3 |
license: other
|
| 4 |
license_link: https://github.com/NVlabs/SegFormer/blob/master/LICENSE
|
| 5 |
base_model: nvidia/segformer-b5-finetuned-cityscapes-1024-1024
|
| 6 |
+
library_name: zeromodels
|
| 7 |
tags:
|
| 8 |
- keras
|
| 9 |
+
- zeromodels
|
| 10 |
- segformer
|
| 11 |
- semantic-segmentation
|
| 12 |
- image-segmentation
|
|
|
|
| 17 |
- tf
|
| 18 |
---
|
| 19 |
|
| 20 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/segformer-6a6a8b9fc36ea6adef0c1616) for all versions of SegFormer.***
|
| 21 |
|
| 22 |
# Run SegFormer with Keras 3: JAX, PyTorch, or TensorFlow
|
| 23 |
|
| 24 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/segformer/) [](https://huggingface.co/collections/zeromodels/segformer-6a6a8b9fc36ea6adef0c1616)
|
| 25 |
|
| 26 |
+
# zeromodels/segformer_b5_cityscapes_1024
|
| 27 |
|
| 28 |
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)
|
| 29 |
|
|
|
|
| 31 |
|
| 32 |
For more details on the model, please go to NVIDIA's original [model card](https://huggingface.co/nvidia/segformer-b5-finetuned-cityscapes-1024-1024).
|
| 33 |
|
| 34 |
+
Pure-**Keras 3** conversion of [`nvidia/segformer-b5-finetuned-cityscapes-1024-1024`](https://huggingface.co/nvidia/segformer-b5-finetuned-cityscapes-1024-1024) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 35 |
|
| 36 |
This is a **semantic segmentation** checkpoint (`SegFormerSemanticSegment`) for **Cityscapes** (19 classes, MiT-B5, 1024px).
|
| 37 |
|
|
|
|
| 42 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 43 |
|
| 44 |
from PIL import Image
|
| 45 |
+
from zeromodels.models.segformer import (
|
| 46 |
SegFormerSemanticSegment,
|
| 47 |
SegFormerImageProcessor,
|
| 48 |
)
|
| 49 |
|
| 50 |
+
model = SegFormerSemanticSegment.from_weights("zeromodels/segformer_b5_cityscapes_1024")
|
| 51 |
+
processor = SegFormerImageProcessor.from_weights("zeromodels/segformer_b5_cityscapes_1024")
|
| 52 |
|
| 53 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 54 |
output = model(processor(image)["pixel_values"], training=False)
|
|
|
|
| 58 |
print(result["unique_classes"], result["class_names"])
|
| 59 |
```
|
| 60 |
|
| 61 |
+
Load any SegFormer variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 62 |
|
| 63 |
| Variant | Hub | Dataset | Res |
|
| 64 |
|---|---|---|---|
|
| 65 |
+
| `segformer_b0_ade_512` | [`zeromodels/segformer_b0_ade_512`](https://huggingface.co/zeromodels/segformer_b0_ade_512) | ADE20K | 512 |
|
| 66 |
+
| `segformer_b1_ade_512` | [`zeromodels/segformer_b1_ade_512`](https://huggingface.co/zeromodels/segformer_b1_ade_512) | ADE20K | 512 |
|
| 67 |
+
| `segformer_b2_ade_512` | [`zeromodels/segformer_b2_ade_512`](https://huggingface.co/zeromodels/segformer_b2_ade_512) | ADE20K | 512 |
|
| 68 |
+
| `segformer_b3_ade_512` | [`zeromodels/segformer_b3_ade_512`](https://huggingface.co/zeromodels/segformer_b3_ade_512) | ADE20K | 512 |
|
| 69 |
+
| `segformer_b4_ade_512` | [`zeromodels/segformer_b4_ade_512`](https://huggingface.co/zeromodels/segformer_b4_ade_512) | ADE20K | 512 |
|
| 70 |
+
| `segformer_b5_ade_640` | [`zeromodels/segformer_b5_ade_640`](https://huggingface.co/zeromodels/segformer_b5_ade_640) | ADE20K | 640 |
|
| 71 |
+
| `segformer_b0_cityscapes_768` | [`zeromodels/segformer_b0_cityscapes_768`](https://huggingface.co/zeromodels/segformer_b0_cityscapes_768) | Cityscapes | 768 |
|
| 72 |
+
| `segformer_b0_cityscapes_1024` | [`zeromodels/segformer_b0_cityscapes_1024`](https://huggingface.co/zeromodels/segformer_b0_cityscapes_1024) | Cityscapes | 1024 |
|
| 73 |
+
| `segformer_b1_cityscapes_1024` | [`zeromodels/segformer_b1_cityscapes_1024`](https://huggingface.co/zeromodels/segformer_b1_cityscapes_1024) | Cityscapes | 1024 |
|
| 74 |
+
| `segformer_b2_cityscapes_1024` | [`zeromodels/segformer_b2_cityscapes_1024`](https://huggingface.co/zeromodels/segformer_b2_cityscapes_1024) | Cityscapes | 1024 |
|
| 75 |
+
| `segformer_b3_cityscapes_1024` | [`zeromodels/segformer_b3_cityscapes_1024`](https://huggingface.co/zeromodels/segformer_b3_cityscapes_1024) | Cityscapes | 1024 |
|
| 76 |
+
| `segformer_b4_cityscapes_1024` | [`zeromodels/segformer_b4_cityscapes_1024`](https://huggingface.co/zeromodels/segformer_b4_cityscapes_1024) | Cityscapes | 1024 |
|
| 77 |
+
| `segformer_b5_cityscapes_1024` | [`zeromodels/segformer_b5_cityscapes_1024`](https://huggingface.co/zeromodels/segformer_b5_cityscapes_1024) | Cityscapes | 1024 |
|
| 78 |
|
| 79 |
## Tips
|
| 80 |
|
| 81 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 82 |
- Prefer `SegFormerImageProcessor.from_weights(...)` so the resize matches the variant (ADE B5 is 640; Cityscapes is often 1024).
|
| 83 |
+
- See [SegFormer docs](https://imvision12.github.io/ZeroModels/segformer/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 84 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `SegFormerSemanticSegment.from_weights("hf:nvidia/segformer-b5-finetuned-cityscapes-1024-1024")`.
|
| 85 |
|
| 86 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,29 +1,29 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "SegFormerSemanticSegment",
|
| 6 |
-
"variant": "segformer_b5_cityscapes_1024",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "segformer",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"embed_dim": [
|
| 13 |
-
64,
|
| 14 |
-
128,
|
| 15 |
-
320,
|
| 16 |
-
512
|
| 17 |
-
],
|
| 18 |
-
"depths": [
|
| 19 |
-
3,
|
| 20 |
-
6,
|
| 21 |
-
40,
|
| 22 |
-
3
|
| 23 |
-
],
|
| 24 |
-
"decode_head_dim": 768,
|
| 25 |
-
"dropout_rate": 0.1,
|
| 26 |
-
"num_classes": 19,
|
| 27 |
-
"image_size": 1024
|
| 28 |
-
}
|
| 29 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.segformer",
|
| 5 |
+
"model_class": "SegFormerSemanticSegment",
|
| 6 |
+
"variant": "segformer_b5_cityscapes_1024",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "segformer",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"embed_dim": [
|
| 13 |
+
64,
|
| 14 |
+
128,
|
| 15 |
+
320,
|
| 16 |
+
512
|
| 17 |
+
],
|
| 18 |
+
"depths": [
|
| 19 |
+
3,
|
| 20 |
+
6,
|
| 21 |
+
40,
|
| 22 |
+
3
|
| 23 |
+
],
|
| 24 |
+
"decode_head_dim": 768,
|
| 25 |
+
"dropout_rate": 0.1,
|
| 26 |
+
"num_classes": 19,
|
| 27 |
+
"image_size": 1024
|
| 28 |
+
}
|
| 29 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "SegFormerImageProcessor",
|
| 6 |
-
"variant": null,
|
| 7 |
-
"do_resize": true,
|
| 8 |
-
"size": {
|
| 9 |
-
"height": 1024,
|
| 10 |
-
"width": 1024
|
| 11 |
-
},
|
| 12 |
-
"resample": "bilinear",
|
| 13 |
-
"do_rescale": true,
|
| 14 |
-
"rescale_factor": 0.00392156862745098,
|
| 15 |
-
"do_normalize": true,
|
| 16 |
-
"image_mean": [
|
| 17 |
-
0.485,
|
| 18 |
-
0.456,
|
| 19 |
-
0.406
|
| 20 |
-
],
|
| 21 |
-
"image_std": [
|
| 22 |
-
0.229,
|
| 23 |
-
0.224,
|
| 24 |
-
0.225
|
| 25 |
-
],
|
| 26 |
-
"return_tensor": true,
|
| 27 |
-
"data_format": null
|
| 28 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.1.3",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.segformer",
|
| 5 |
+
"preprocessor_class": "SegFormerImageProcessor",
|
| 6 |
+
"variant": null,
|
| 7 |
+
"do_resize": true,
|
| 8 |
+
"size": {
|
| 9 |
+
"height": 1024,
|
| 10 |
+
"width": 1024
|
| 11 |
+
},
|
| 12 |
+
"resample": "bilinear",
|
| 13 |
+
"do_rescale": true,
|
| 14 |
+
"rescale_factor": 0.00392156862745098,
|
| 15 |
+
"do_normalize": true,
|
| 16 |
+
"image_mean": [
|
| 17 |
+
0.485,
|
| 18 |
+
0.456,
|
| 19 |
+
0.406
|
| 20 |
+
],
|
| 21 |
+
"image_std": [
|
| 22 |
+
0.229,
|
| 23 |
+
0.224,
|
| 24 |
+
0.225
|
| 25 |
+
],
|
| 26 |
+
"return_tensor": true,
|
| 27 |
+
"data_format": null
|
| 28 |
}
|