Xrenya commited on
Commit
864d3bb
·
1 Parent(s): 0303e93

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +82 -0
README.md CHANGED
@@ -1,3 +1,85 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ tags:
4
+ - vision
5
+ - image-classification
6
+ datasets:
7
+ - imagenet-1k
8
+ widget:
9
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg
10
+ example_title: Tiger
11
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg
12
+ example_title: Teapot
13
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
14
+ example_title: Palace
15
  ---
16
+
17
+ # Pyramid Vision Transformer (tiny-sized model)
18
+
19
+ Pyramid Vision Transformer (PVT) model pre-trained on ImageNet-1K (1 million images, 1000 classes) at resolution 224x224, and fine-tuned on ImageNet 2012 (1 million images, 1,000 classes) at resolution 224x224. It was introduced in the paper [Pyramid Vision Transformer: A Versatile Backbone for Dense Prediction without Convolutions](https://arxiv.org/abs/2102.12122) by Wenhai Wang, Enze Xie, Xiang Li, Deng-Ping Fan, Kaitao Song, Ding Liang, Tong Lu, Ping Luo, Ling Shao and first released in [this repository](https://github.com/whai362/PVT).
20
+
21
+ Disclaimer: The team releasing PVT did not write a model card for this model so this model card has been written by [Rinat S. [@Xrenya]](https://huggingface.co/Xrenya).
22
+
23
+ ## Model description
24
+
25
+ The Pyramid Vision Transformer (PVT) is a transformer encoder model (BERT-like) pretrained on ImageNet-1k (also referred to as ILSVRC2012), a dataset comprising 1 million images and 1,000 classes, also at resolution 224x224.
26
+
27
+ Images are presented to the model as a sequence of variable-size patches, which are linearly embedded. Unlike ViT models, PVT is using a progressive shrinking pyramid to reduce computations of large feature maps at each stage. One also adds a [CLS] token to the beginning of a sequence to use it for classification tasks. One also adds absolute position embeddings before feeding the sequence to the layers of the Transformer encoder.
28
+
29
+ By pre-training the model, it learns an inner representation of images that can then be used to extract features useful for downstream tasks: if you have a dataset of labeled images for instance, you can train a standard classifier by placing a linear layer on top of the pre-trained encoder. One typically places a linear layer on top of the [CLS] token, as the last hidden state of this token can be seen as a representation of an entire image.
30
+
31
+ ## Intended uses & limitations
32
+
33
+ You can use the raw model for image classification. See the [model hub](https://huggingface.co/Xrenya) to look for
34
+ fine-tuned versions on a task that interests you.
35
+
36
+ ### How to use
37
+
38
+ Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:
39
+
40
+ ```python
41
+ from transformers import PVTImageProcessor, PVTForImageClassification
42
+ from PIL import Image
43
+ import requests
44
+
45
+ url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
46
+ image = Image.open(requests.get(url, stream=True).raw)
47
+
48
+ processor = PVTImageProcessor.from_pretrained('Xrenya/pvt-large-224')
49
+ model = PVTForImageClassification.from_pretrained('Xrenya/pvt-large-224')
50
+
51
+ inputs = processor(images=image, return_tensors="pt")
52
+ outputs = model(**inputs)
53
+ logits = outputs.logits
54
+ # model predicts one of the 1000 ImageNet classes
55
+ predicted_class_idx = logits.argmax(-1).item()
56
+ print("Predicted class:", model.config.id2label[predicted_class_idx])
57
+ ```
58
+
59
+ For more code examples, we refer to the [documentation](https://huggingface.co/transformers/model_doc/pvt.html#).
60
+
61
+ ## Training data
62
+
63
+ The ViT model was pretrained on [ImageNet-1k](http://www.image-net.org/challenges/LSVRC/2012/), a dataset consisting of 1 million images and 1k classes.
64
+
65
+ ## Training procedure
66
+
67
+ ### Preprocessing
68
+
69
+ The exact details of preprocessing of images during training/validation can be found [here](https://github.com/whai362/PVT/blob/v2/classification/datasets.py).
70
+
71
+ Images are resized/rescaled to the same resolution (224x224) and normalized across the RGB channels with mean (0.485, 0.456, 0.406) and standard deviation (0.229, 0.224, 0.225).
72
+
73
+
74
+
75
+ ### BibTeX entry and citation info
76
+
77
+ ```bibtex
78
+ @inproceedings{wang2021pyramid,
79
+ title={Pyramid vision transformer: A versatile backbone for dense prediction without convolutions},
80
+ author={Wang, Wenhai and Xie, Enze and Li, Xiang and Fan, Deng-Ping and Song, Kaitao and Liang, Ding and Lu, Tong and Luo, Ping and Shao, Ling},
81
+ booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
82
+ pages={568--578},
83
+ year={2021}
84
+ }
85
+ ```