CoolFace
Modelpublic

microsoft/swin-base-patch4-window7-224

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
27likes46kdownloads
README.md84 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 (base-sized model) 18 19Swin Transformer model trained on ImageNet-1k at resolution 224x224. It was introduced in the paper [Swin Transformer: Hierarchical Vision Transformer using Shifted Windows](https://arxiv.org/abs/2103.14030) by Liu et al. and first released in [this repository](https://github.com/microsoft/Swin-Transformer). 20 21Disclaimer: The team releasing Swin Transformer 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 27![model image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/swin_transformer_architecture.png)28 29[Source](https://paperswithcode.com/method/swin-transformer)30 31## Intended uses & limitations32 33You can use the raw model for image classification. See the [model hub](https://huggingface.co/models?search=swin) to look for34fine-tuned versions on a task that interests you.35 36### How to use37 38Here 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```python41from transformers import AutoFeatureExtractor, SwinForImageClassification42from PIL import Image43import requests44 45url = "http://images.cocodataset.org/val2017/000000039769.jpg"46image = Image.open(requests.get(url, stream=True).raw)47 48feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/swin-base-patch4-window7-224")49model = SwinForImageClassification.from_pretrained("microsoft/swin-base-patch4-window7-224")50 51inputs = feature_extractor(images=image, return_tensors="pt")52outputs = model(**inputs)53logits = outputs.logits54# model predicts one of the 1000 ImageNet classes55predicted_class_idx = logits.argmax(-1).item()56print("Predicted class:", model.config.id2label[predicted_class_idx])57```58 59For more code examples, we refer to the [documentation](https://huggingface.co/transformers/model_doc/swin.html#).60 61### BibTeX entry and citation info62 63```bibtex64@article{DBLP:journals/corr/abs-2103-14030,65  author    = {Ze Liu and66               Yutong Lin and67               Yue Cao and68               Han Hu and69               Yixuan Wei and70               Zheng Zhang and71               Stephen Lin and72               Baining Guo},73  title     = {Swin Transformer: Hierarchical Vision Transformer using Shifted Windows},74  journal   = {CoRR},75  volume    = {abs/2103.14030},76  year      = {2021},77  url       = {https://arxiv.org/abs/2103.14030},78  eprinttype = {arXiv},79  eprint    = {2103.14030},80  timestamp = {Thu, 08 Apr 2021 07:53:26 +0200},81  biburl    = {https://dblp.org/rec/journals/corr/abs-2103-14030.bib},82  bibsource = {dblp computer science bibliography, https://dblp.org}83}84```