Divyasreepat
commited on
Commit
•
856f672
1
Parent(s):
981e8f4
Update README.md with new model card content
Browse files
README.md
CHANGED
@@ -1,13 +1,124 @@
|
|
1 |
---
|
2 |
library_name: keras-hub
|
3 |
---
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
* **trainable:** True
|
10 |
-
* **projection_filters:** 768
|
11 |
-
* **image_encoder:** {'module': 'keras_hub.src.models.mit.mit_backbone', 'class_name': 'MiTBackbone', 'config': {'name': 'mi_t_backbone', 'trainable': True, 'layerwise_depths': [3, 4, 18, 3], 'hidden_dims': [64, 128, 320, 512], 'image_shape': [512, 512, 3], 'num_layers': 4, 'layerwise_num_heads': [1, 2, 5, 8], 'layerwise_sr_ratios': [8, 4, 2, 1], 'max_drop_path_rate': 0.1, 'layerwise_patch_sizes': [7, 3, 3, 3], 'layerwise_strides': [4, 2, 2, 2]}, 'registered_name': 'keras_hub>MiTBackbone'}
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
library_name: keras-hub
|
3 |
---
|
4 |
+
### Model Overview
|
5 |
+
The SegFormer model was proposed in SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Enze Xie, Wenhai Wang, Zhiding Yu, Anima Anandkumar, Jose M. Alvarez, Ping Luo. The model consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on image segmentation benchmarks such as ADE20K and Cityscapes.
|
6 |
|
7 |
+
`
|
8 |
+
Weights are released under the [MIT License](https://opensource.org/license/mit). Keras model code is released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE).
|
|
|
|
|
|
|
9 |
|
10 |
+
## Links
|
11 |
+
|
12 |
+
* [Segmentation Quickstart Notebook](https://www.kaggle.com/code/divyasss/deeplabv3plus-quickstart)
|
13 |
+
* [SegFormer API Documentation](https://keras.io/api/keras_cv/models/tasks/segformer_b0)
|
14 |
+
* [SegFormer Model Card](https://huggingface.co/docs/transformers/en/model_doc/segformer)
|
15 |
+
|
16 |
+
|
17 |
+
## Installation
|
18 |
+
|
19 |
+
Keras and KerasCV can be installed with:
|
20 |
+
|
21 |
+
```
|
22 |
+
pip install -U -q keras-cv
|
23 |
+
pip install -U -q keras>=3
|
24 |
+
```
|
25 |
+
|
26 |
+
Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page.
|
27 |
+
|
28 |
+
## Presets
|
29 |
+
|
30 |
+
The following model checkpoints are provided by the Keras team. Full code examples for each are available below.
|
31 |
+
| Preset name | Parameters | Description |
|
32 |
+
|-----------------------|------------|---------------------------------------------------|
|
33 |
+
| segformer_b0_imagenet | 3.72M | SegFormer model with a pretrained MiTB0 backbone. |
|
34 |
+
| segformer_b0 | 3.72M | SegFormer model with MiTB0 backbone. |
|
35 |
+
| segformer_b1 | 13.68M | SegFormer model with MiTB1 backbone. |
|
36 |
+
| segformer_b2 | 24.73M | SegFormer model with MiTB2 backbone. |
|
37 |
+
| segformer_b3 | 44.60M | SegFormer model with MiTB3 backbone. |
|
38 |
+
| segformer_b4 | 61.37M | SegFormer model with MiTB4 backbone. |
|
39 |
+
| segformer_b5 | 81.97M | SegFormer model with MiTB5 backbone. |
|
40 |
+
|
41 |
+
## Example code
|
42 |
+
|
43 |
+
```Python
|
44 |
+
import keras_cv
|
45 |
+
|
46 |
+
images = np.ones(shape=(1, 224, 224, 3))
|
47 |
+
labels = np.zeros(shape=(1, 224, 224, 1))
|
48 |
+
|
49 |
+
|
50 |
+
model = keras_cv.models.SegFormer.from_preset(
|
51 |
+
"segformer_b0", num_classes=2
|
52 |
+
)
|
53 |
+
# Evaluate model
|
54 |
+
model(images)
|
55 |
+
```
|
56 |
+
|
57 |
+
## Example Usage
|
58 |
+
```python
|
59 |
+
import keras_cv
|
60 |
+
import keras
|
61 |
+
import numpy as np
|
62 |
+
```
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
Using the class with a `backbone`:
|
67 |
+
|
68 |
+
```python
|
69 |
+
import tensorflow as tf
|
70 |
+
import keras_cv
|
71 |
+
|
72 |
+
images = np.ones(shape=(1, 96, 96, 3))
|
73 |
+
labels = np.zeros(shape=(1, 96, 96, 1))
|
74 |
+
backbone = keras_cv.models.MiTBackbone.from_preset("segformer_b3_ade20k_512")
|
75 |
+
model = keras_cv.models.segmentation.SegFormer(
|
76 |
+
num_classes=1, backbone=backbone,
|
77 |
+
)
|
78 |
+
|
79 |
+
# Evaluate model
|
80 |
+
model(images)
|
81 |
+
|
82 |
+
# Train model
|
83 |
+
model.compile(
|
84 |
+
optimizer="adam",
|
85 |
+
loss=keras.losses.BinaryCrossentropy(from_logits=False),
|
86 |
+
metrics=["accuracy"],
|
87 |
+
)
|
88 |
+
model.fit(images, labels, epochs=3)
|
89 |
+
```
|
90 |
+
|
91 |
+
## Example Usage with Hugging Face URI
|
92 |
+
|
93 |
+
```python
|
94 |
+
import keras_cv
|
95 |
+
import keras
|
96 |
+
import numpy as np
|
97 |
+
```
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
Using the class with a `backbone`:
|
102 |
+
|
103 |
+
```python
|
104 |
+
import tensorflow as tf
|
105 |
+
import keras_cv
|
106 |
+
|
107 |
+
images = np.ones(shape=(1, 96, 96, 3))
|
108 |
+
labels = np.zeros(shape=(1, 96, 96, 1))
|
109 |
+
backbone = keras_cv.models.MiTBackbone.from_preset("hf://keras/segformer_b3_ade20k_512")
|
110 |
+
model = keras_cv.models.segmentation.SegFormer(
|
111 |
+
num_classes=1, backbone=backbone,
|
112 |
+
)
|
113 |
+
|
114 |
+
# Evaluate model
|
115 |
+
model(images)
|
116 |
+
|
117 |
+
# Train model
|
118 |
+
model.compile(
|
119 |
+
optimizer="adam",
|
120 |
+
loss=keras.losses.BinaryCrossentropy(from_logits=False),
|
121 |
+
metrics=["accuracy"],
|
122 |
+
)
|
123 |
+
model.fit(images, labels, epochs=3)
|
124 |
+
```
|