Update README.md
Browse files
README.md
CHANGED
@@ -16,7 +16,29 @@ SegFormer model fine-tuned on SegmentsAI [`sidewalk-semantic`](https://huggingfa
|
|
16 |
## Model description
|
17 |
SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a downstream dataset.
|
18 |
|
19 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
You can go through its detailed notebook [here](https://github.com/ZohebAbai/Deep-Learning-Projects/blob/master/09_HF_Image_Segmentation_using_Transformers.ipynb).
|
21 |
|
22 |
For more code examples, refer to the [documentation](https://huggingface.co/transformers/model_doc/segformer.html#).
|
|
|
16 |
## Model description
|
17 |
SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a downstream dataset.
|
18 |
|
19 |
+
## Code and Notebook
|
20 |
+
Here is how to use this model to classify an image of the sidewalk dataset:
|
21 |
+
|
22 |
+
```python
|
23 |
+
from transformers import SegformerFeatureExtractor, SegformerForImageClassification
|
24 |
+
from PIL import Image
|
25 |
+
import requests
|
26 |
+
|
27 |
+
url = "https://segmentsai-prod.s3.eu-west-2.amazonaws.com/assets/admin-tobias/439f6843-80c5-47ce-9b17-0b2a1d54dbeb.jpg"
|
28 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
29 |
+
|
30 |
+
feature_extractor = SegformerFeatureExtractor.from_pretrained("zoheb/mit-b5-finetuned-sidewalk-semantic")
|
31 |
+
model = SegformerForImageClassification.from_pretrained("zoheb/mit-b5-finetuned-sidewalk-semantic")
|
32 |
+
|
33 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
34 |
+
outputs = model(**inputs)
|
35 |
+
logits = outputs.logits
|
36 |
+
|
37 |
+
# model predicts one of the 35 Sidewalk classes
|
38 |
+
predicted_class_idx = logits.argmax(-1).item()
|
39 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
40 |
+
```
|
41 |
+
|
42 |
You can go through its detailed notebook [here](https://github.com/ZohebAbai/Deep-Learning-Projects/blob/master/09_HF_Image_Segmentation_using_Transformers.ipynb).
|
43 |
|
44 |
For more code examples, refer to the [documentation](https://huggingface.co/transformers/model_doc/segformer.html#).
|