CoolFace
Modelpublic

microsoft/swinv2-small-patch4-window8-256

sourceHugging Faceapache-2.0updated 4y agoView on Hugging Face
0likes1.8kdownloads
README.md90 linesDownload Raw Back to root
1---2license: apache-2.03tags:4- vision5- image-classification6datasets:7- imagenet-1k8widget:9- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg10  example_title: Tiger11- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg12  example_title: Teapot13- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg14  example_title: Palace15---16 17# Swin Transformer v2 (small-sized model) 18 19Swin Transformer v2 model pre-trained on ImageNet-1k at resolution 256x256. It was introduced in the paper [Swin Transformer V2: Scaling Up Capacity and Resolution](https://arxiv.org/abs/2111.09883) by Liu et al. and first released in [this repository](https://github.com/microsoft/Swin-Transformer). 20 21Disclaimer: The team releasing Swin Transformer v2 did not write a model card for this model so this model card has been written by the Hugging Face team.22 23## Model description24 25The Swin Transformer is a type of Vision Transformer. It builds hierarchical feature maps by merging image patches (shown in gray) in deeper layers and has linear computation complexity to input image size due to computation of self-attention only within each local window (shown in red). It can thus serve as a general-purpose backbone for both image classification and dense recognition tasks. In contrast, previous vision Transformers produce feature maps of a single low resolution and have quadratic computation complexity to input image size due to computation of self-attention globally.26 27Swin Transformer v2 adds 3 main improvements: 1) a residual-post-norm method combined with cosine attention to improve training stability; 2) a log-spaced continuous position bias method to effectively transfer models pre-trained using low-resolution images to downstream tasks with high-resolution inputs; 3) a self-supervised pre-training method, SimMIM, to reduce the needs of vast labeled images.28 29![model image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/swin_transformer_architecture.png)30 31[Source](https://paperswithcode.com/method/swin-transformer)32 33## Intended uses & limitations34 35You can use the raw model for image classification. See the [model hub](https://huggingface.co/models?search=swinv2) to look for36fine-tuned versions on a task that interests you.37 38### How to use39 40Here is how to use this model to classify an image of the COCO 2017 dataset into one of the 1,000 ImageNet classes:41 42```python43from transformers import AutoImageProcessor, AutoModelForImageClassification44from PIL import Image45import requests46 47url = "http://images.cocodataset.org/val2017/000000039769.jpg"48image = Image.open(requests.get(url, stream=True).raw)49 50processor = AutoImageProcessor.from_pretrained("microsoft/swinv2-small-patch4-window8-256")51model = AutoModelForImageClassification.from_pretrained("microsoft/swinv2-small-patch4-window8-256")52 53inputs = processor(images=image, return_tensors="pt")54outputs = model(**inputs)55logits = outputs.logits56# model predicts one of the 1000 ImageNet classes57predicted_class_idx = logits.argmax(-1).item()58print("Predicted class:", model.config.id2label[predicted_class_idx])59```60 61For more code examples, we refer to the [documentation](https://huggingface.co/transformers/model_doc/swinv2.html#).62 63### BibTeX entry and citation info64 65```bibtex66@article{DBLP:journals/corr/abs-2111-09883,67  author    = {Ze Liu and68               Han Hu and69               Yutong Lin and70               Zhuliang Yao and71               Zhenda Xie and72               Yixuan Wei and73               Jia Ning and74               Yue Cao and75               Zheng Zhang and76               Li Dong and77               Furu Wei and78               Baining Guo},79  title     = {Swin Transformer {V2:} Scaling Up Capacity and Resolution},80  journal   = {CoRR},81  volume    = {abs/2111.09883},82  year      = {2021},83  url       = {https://arxiv.org/abs/2111.09883},84  eprinttype = {arXiv},85  eprint    = {2111.09883},86  timestamp = {Thu, 02 Dec 2021 15:54:22 +0100},87  biburl    = {https://dblp.org/rec/journals/corr/abs-2111-09883.bib},88  bibsource = {dblp computer science bibliography, https://dblp.org}89}90```