README.md
3.3 KB · 82 lines · markdown Raw
1 ---
2 license: other
3 tags:
4 - vision
5 datasets:
6 - imagenet_1k
7 widget:
8 - src: https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg
9 example_title: House
10 - src: https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000002.jpg
11 example_title: Castle
12 ---
13
14 # SegFormer (b2-sized) encoder pre-trained-only
15
16 SegFormer encoder fine-tuned on Imagenet-1k. It was introduced in the paper [SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers](https://arxiv.org/abs/2105.15203) by Xie et al. and first released in [this repository](https://github.com/NVlabs/SegFormer).
17
18 Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team.
19
20 ## Model description
21
22 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.
23
24 This repository only contains the pre-trained hierarchical Transformer, hence it can be used for fine-tuning purposes.
25
26 ## Intended uses & limitations
27
28 You can use the model for fine-tuning of semantic segmentation. See the [model hub](https://huggingface.co/models?other=segformer) to look for fine-tuned versions on a task that interests you.
29
30 ### How to use
31
32 Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
33
34 ```python
35 from transformers import SegformerFeatureExtractor, SegformerForImageClassification
36 from PIL import Image
37 import requests
38
39 url = "http://images.cocodataset.org/val2017/000000039769.jpg"
40 image = Image.open(requests.get(url, stream=True).raw)
41
42 feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/mit-b2")
43 model = SegformerForImageClassification.from_pretrained("nvidia/mit-b2")
44
45 inputs = feature_extractor(images=image, return_tensors="pt")
46 outputs = model(**inputs)
47 logits = outputs.logits
48 # model predicts one of the 1000 ImageNet classes
49 predicted_class_idx = logits.argmax(-1).item()
50 print("Predicted class:", model.config.id2label[predicted_class_idx])
51 ```
52
53 For more code examples, we refer to the [documentation](https://huggingface.co/transformers/model_doc/segformer.html#).
54
55 ### License
56
57 The license for this model can be found [here](https://github.com/NVlabs/SegFormer/blob/master/LICENSE).
58
59 ### BibTeX entry and citation info
60
61 ```bibtex
62 @article{DBLP:journals/corr/abs-2105-15203,
63 author = {Enze Xie and
64 Wenhai Wang and
65 Zhiding Yu and
66 Anima Anandkumar and
67 Jose M. Alvarez and
68 Ping Luo},
69 title = {SegFormer: Simple and Efficient Design for Semantic Segmentation with
70 Transformers},
71 journal = {CoRR},
72 volume = {abs/2105.15203},
73 year = {2021},
74 url = {https://arxiv.org/abs/2105.15203},
75 eprinttype = {arXiv},
76 eprint = {2105.15203},
77 timestamp = {Wed, 02 Jun 2021 11:46:42 +0200},
78 biburl = {https://dblp.org/rec/journals/corr/abs-2105-15203.bib},
79 bibsource = {dblp computer science bibliography, https://dblp.org}
80 }
81 ```
82