File size: 5,765 Bytes
17c6d62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# Swin Transformer [[swin-transformer]]
## ๊ฐ์ [[overview]]
Swin Transformer๋ Ze Liu, Yutong Lin, Yue Cao, Han Hu, Yixuan Wei, Zheng Zhang, Stephen Lin, Baining Guo๊ฐ ์ ์ํ ๋
ผ๋ฌธ [Swin Transformer: Hierarchical Vision Transformer using Shifted Windows](https://arxiv.org/abs/2103.14030)์์ ์๊ฐ๋์์ต๋๋ค.
๋
ผ๋ฌธ์ ์ด๋ก์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
*์ด ๋
ผ๋ฌธ์ Swin Transformer๋ผ๋ ์๋ก์ด ๋น์ ํธ๋์คํฌ๋จธ๋ฅผ ์๊ฐํฉ๋๋ค. ์ด ๋ชจ๋ธ์ ์ปดํจํฐ ๋น์ ์์ ๋ฒ์ฉ ๋ฐฑ๋ณธ(backbone)์ผ๋ก ์ฌ์ฉ๋ ์ ์์ต๋๋ค. ํธ๋์คํฌ๋จธ๋ฅผ ์ธ์ด์์ ๋น์ ์ผ๋ก ์ ์ฉํ ๋์ ์ด๋ ค์์ ๋ ๋ถ์ผ ๊ฐ์ ์ฐจ์ด์์ ๋น๋กฏ๋๋๋ฐ, ์๋ฅผ ๋ค์ด ์๊ฐ์ ๊ฐ์ฒด์ ํฌ๊ธฐ๊ฐ ํฌ๊ฒ ๋ณ๋ํ๋ฉฐ, ์ด๋ฏธ์ง์ ํฝ์
ํด์๋๊ฐ ํ
์คํธ์ ๋จ์ด์ ๋นํด ๋งค์ฐ ๋๋ค๋ ์ ์ด ์์ต๋๋ค. ์ด๋ฌํ ์ฐจ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด, ์ฐ๋ฆฌ๋ 'Shifted Windows'๋ฅผ ์ด์ฉํด ํํ์ ๊ณ์ฐํ๋ ๊ณ์ธต์ ํธ๋์คํฌ๋จธ๋ฅผ ์ ์ํฉ๋๋ค. Shifted Windows ๋ฐฉ์์ ๊ฒน์น์ง ์๋ ๋ก์ปฌ ์๋์ฐ์์ self-attention ๊ณ์ฐ์ ์ ํํ์ฌ ํจ์จ์ฑ์ ๋์ด๋ ๋์์ ์๋์ฐ ๊ฐ ์ฐ๊ฒฐ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค. ์ด ๊ณ์ธต์ ๊ตฌ์กฐ๋ ๋ค์ํ ํฌ๊ธฐ์ ํจํด์ ๋ชจ๋ธ๋งํ ์ ์๋ ์ ์ฐ์ฑ์ ์ ๊ณตํ๋ฉฐ, ์ด๋ฏธ์ง ํฌ๊ธฐ์ ๋น๋กํ ์ ํ ๊ณ์ฐ ๋ณต์ก์ฑ์ ๊ฐ์ง๊ณ ์์ต๋๋ค. Swin Transformer์ ์ด๋ฌํ ํน์ง๋ค์ ์ด๋ฏธ์ง ๋ถ๋ฅ(Imagenet-1K์์ 87.3์ top-1 ์ ํ๋) ๋ฐ ๊ฐ์ฒด ๊ฒ์ถ(COCO test-dev์์ 58.7์ ๋ฐ์ค AP, 51.1์ ๋ง์คํฌ AP)๊ณผ ๊ฐ์ ๋ฐ์ง ์์ธก ์์
, ์๋ฏธ์ ๋ถํ (ADE20K val์์ 53.5์ mIoU)๊ณผ ๊ฐ์ ๊ด๋ฒ์ํ ๋น์ ์์
์ ์ ํฉํฉ๋๋ค. ์ด ๋ชจ๋ธ์ COCO์์ ์ด์ ์ต๊ณ ์ฑ๋ฅ์ ๋ฐ์ค AP์์ +2.7, ๋ง์คํฌ AP์์ +2.6, ADE20K์์ mIoU์์ +3.2๋ฅผ ์ด๊ณผํ๋ ์ฑ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๋ฉฐ, ํธ๋์คํฌ๋จธ ๊ธฐ๋ฐ ๋ชจ๋ธ์ด ๋น์ ๋ฐฑ๋ณธ์ผ๋ก์์ ์ ์ฌ๋ ฅ์ ์
์ฆํ์ต๋๋ค. ๊ณ์ธต์ ์ค๊ณ์ Shifted Windows ๋ฐฉ์์ ์์ MLP ์ํคํ
์ฒ์๋ ์ ๋ฆฌํ๊ฒ ์์ฉํฉ๋๋ค.*
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/swin_transformer_architecture.png"
alt="drawing" width="600"/>
<small> Swin Transformer ์ํคํ
์ฒ. <a href="https://arxiv.org/abs/2102.03334">์๋ณธ ๋
ผ๋ฌธ</a>์์ ๋ฐ์ท.</small>
์ด ๋ชจ๋ธ์ [novice03](https://huggingface.co/novice03)์ด ๊ธฐ์ฌํ์์ต๋๋ค. Tensorflow ๋ฒ์ ์ [amyeroberts](https://huggingface.co/amyeroberts)๊ฐ ๊ธฐ์ฌํ์ต๋๋ค. ์๋ณธ ์ฝ๋๋ [์ฌ๊ธฐ](https://github.com/microsoft/Swin-Transformer)์์ ํ์ธํ ์ ์์ต๋๋ค.
## ์ฌ์ฉ ํ [[usage-tips]]
- Swin์ ์
๋ ฅ์ ๋์ด์ ๋๋น๊ฐ `32`๋ก ๋๋์ด์ง ์ ์์ผ๋ฉด ์ด๋ค ํฌ๊ธฐ๋ ์ง์ํ ์ ์๋๋ก ํจ๋ฉ์ ์ถ๊ฐํฉ๋๋ค.
- Swin์ *๋ฐฑ๋ณธ*์ผ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค. `output_hidden_states = True`๋ก ์ค์ ํ๋ฉด, `hidden_states`์ `reshaped_hidden_states`๋ฅผ ๋ชจ๋ ์ถ๋ ฅํฉ๋๋ค. `reshaped_hidden_states`๋ `(batch, num_channels, height, width)` ํ์์ ๊ฐ์ง๋ฉฐ, ์ด๋ `(batch_size, sequence_length, num_channels)` ํ์๊ณผ ๋ค๋ฆ
๋๋ค.
## ๋ฆฌ์์ค [[resources]]
Swin Transformer์ ์ฌ์ฉ์ ๋์ธ ์ ์๋ Hugging Face ๋ฐ ์ปค๋ฎค๋ํฐ(๐๋ก ํ์)์ ๊ณต์ ์๋ฃ ๋ชฉ๋ก์
๋๋ค.
<PipelineTag pipeline="image-classification"/>
- [`SwinForImageClassification`]์ ์ด [์์ ์คํฌ๋ฆฝํธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification)์ [๋
ธํธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb)์ ํตํด ์ง์๋ฉ๋๋ค.
- ๊ด๋ จ ์๋ฃ: [์ด๋ฏธ์ง ๋ถ๋ฅ ์์
๊ฐ์ด๋](../tasks/image_classification)
๋ํ:
- [`SwinForMaskedImageModeling`]์ ์ด [์์ ์คํฌ๋ฆฝํธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-pretraining)๋ฅผ ํตํด ์ง์๋ฉ๋๋ค.
์๋ก์ด ์๋ฃ๋ฅผ ์ถ๊ฐํ๊ณ ์ถ์ผ์๋ค๋ฉด, ์ธ์ ๋ ์ง Pull Request๋ฅผ ์ด์ด์ฃผ์ธ์! ์ ํฌ๊ฐ ๊ฒํ ํด ๋๋ฆด๊ฒ์. ์ด๋, ์ถ๊ฐํ๋ ์๋ฃ๋ ๊ธฐ์กด ์๋ฃ์ ์ค๋ณต๋์ง ์๊ณ ์๋ก์ด ๋ด์ฉ์ ๋ณด์ฌ์ฃผ๋ ์๋ฃ์ฌ์ผ ํฉ๋๋ค.
## SwinConfig [[transformers.SwinConfig]]
[[autodoc]] SwinConfig
<frameworkcontent>
<pt>
## SwinModel [[transformers.SwinModel]]
[[autodoc]] SwinModel
- forward
## SwinForMaskedImageModeling [[transformers.SwinForMaskedImageModeling]]
[[autodoc]] SwinForMaskedImageModeling
- forward
## SwinForImageClassification [[transformers.SwinForImageClassification]]
[[autodoc]] transformers.SwinForImageClassification
- forward
</pt>
<tf>
## TFSwinModel [[transformers.TFSwinModel]]
[[autodoc]] TFSwinModel
- call
## TFSwinForMaskedImageModeling [[transformers.TFSwinForMaskedImageModeling]]
[[autodoc]] TFSwinForMaskedImageModeling
- call
## TFSwinForImageClassification [[transformers.TFSwinForImageClassification]]
[[autodoc]] transformers.TFSwinForImageClassification
- call
</tf>
</frameworkcontent> |