Swin Transformer
Swin Transformer V1은 전체 이미지가 아니라 이동된 로컬 윈도우 안에서 어텐션을 계산하는 계층적 비전 트랜스포머입니다. LibreYOLO는 이미지 분류용 크기 4개를 제공합니다.
- 작업
- classify
- 크기
- t, s, b, l at 224 px
- 설치
pip install libreyolo- 지원 티어
- 추론 전용, v부터 지원. 예측, 검증, 내보내기만 지원합니다. 학습 기능은 적용되지 않습니다.
- 라이선스
- 코드 Apache-2.0, 가중치 MIT. 상업적 사용
설치
Swin에는 선택적 extra가 필요하지 않습니다. 가져오는 모든 항목이 기본 설치에 포함됩니다.
pip install libreyolo예측
가중치는 처음 사용할 때 Hugging Face에서 내려받아 로컬에 캐시됩니다.
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreSwint-cls.pt")result = model(SAMPLE_IMAGE, save=True) probs = result.probsprint(probs.top1, probs.top1conf)print(probs.top5, probs.top5conf)libreyolo predict model=LibreSwint-cls.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True분류기는 result.boxes 대신 result.probs를 반환합니다. top1과 top5는
클래스 인덱스를, top1conf와 top5conf는 해당 신뢰도를 제공합니다. 마지막
어텐션 단계가 해당 해상도용으로 만들어졌으므로 모든 크기는 224px 입력으로
고정됩니다. 다른 imgsz를 전달하면 예측, 검증, 내보내기에서 모두 오류가
발생합니다. 소스, 스트리밍, 결과 처리는 예측을 참조합니다.
변형
tiny부터 large까지 크기 4개가 있으며 같은 이동 윈도우 타워로 구성되고 임베딩 너비와 단계 깊이가 다릅니다. large는 ImageNet-22k로 사전 학습하고 ImageNet-1k로 파인튜닝했으며, 나머지 3개는 ImageNet-1k에서 직접 학습했습니다. LibreYOLO는 이 계열을 추론 전용으로 제공합니다. 예측, ImageNet 방식 top-1/top-5 검증, 내보내기를 지원하며 업스트림 ImageNet 학습 레시피는 구현되지 않았습니다.
검증
val()은 ImageFolder 방식 분할(train/ 및 val/ 하위 폴더와 클래스별 폴더가
있는 디렉터리)을 대상으로 실행하고 top-1 및 top-5 정확도를 반환합니다.
from libreyolo import LibreYOLO model = LibreYOLO("LibreSwint-cls.pt") # data는 데이터셋 YAML이 아니라 train/ 및 val/ 클래스 폴더 분할이 있는# 디렉터리 루트(ImageFolder 레이아웃)입니다.metrics = model.val(data="imagenet-1k/") print(metrics["metrics/accuracy_top1"])print(metrics["metrics/accuracy_top5"])libreyolo val model=LibreSwint-cls.pt data=imagenet-1k/내보내기
| 작업 | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| classify | classify to ONNX: 지원함 | classify to TorchScript: 지원함 | classify to ExecuTorch: 지원함 | classify to TensorRT: 지원함 | classify to OpenVINO: 지원함 | classify to Paddle: 지원하지 않음 | classify to MNN: 지원하지 않음 | classify to RKNN: 지원하지 않음 | classify to ncnn: 지원함 | classify to TFLite: 지원하지 않음 | classify to CoreML: 지원하지 않음 | classify to Core AI: 지원하지 않음 |
내보낸 아티팩트는 파일 접미사에 따라 LibreYOLO()로 다시 불러오므로 .onnx 또는
.engine 파일이 체크포인트처럼 동작하며 동일한 Results를 반환합니다.
내보내기에는 모든 형식이 허용하는 인수와 일부 형식이 추가하는 extra가
나열되어 있습니다.
from libreyolo import LibreYOLO model = LibreYOLO("LibreSwint-cls.pt")model.export(format="onnx")model.export(format="tensorrt", half=True)libreyolo export model=LibreSwint-cls.pt format=onnxlibreyolo export model=LibreSwint-cls.pt format=tensorrt half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # 팩토리는 파일 접미사로 라우팅하므로 내보낸 아티팩트도# 체크포인트처럼 불러오며 동일한 Results 객체를 반환합니다.model = LibreYOLO("LibreSwint-cls.onnx")result = model(SAMPLE_IMAGE) print(result.probs.top1)체크포인트
이 계열에서 공개된 모든 가중치 파일입니다.
| 파일 | 입력(px) | 가중치 라이선스 |
|---|---|---|
| classify | ||
| LibreSwint-cls.pt | 224 | mit |
| LibreSwins-cls.pt | 224 | mit |
| LibreSwinb-cls.pt | 224 | mit |
| LibreSwinl-cls.pt | 224 | mit |
위의 모든 파일은 현재 LibreYOLO 조직에 있으며 처음 사용할 때 내려받습니다.
라이선스
내려받는 특정 가중치의 Hugging Face 저장소에서 라이선스를 확인하십시오. LibreYOLO 조직의 모든 체크포인트에는 라이선스가 있으며 한 계열 안에서도 항상 같지는 않습니다. 해당 저장소가 신뢰할 수 있는 기준입니다. 아래 요약은 이 페이지를 마지막으로 검증했을 때 적용된 내용을 설명합니다.
관련 라이선스에 관한 설명이며 법률 자문이 아닙니다. 상업적으로 중요한 사안이라면 라이선스를 직접 읽고 별도의 법률 자문을 받으십시오.
- 원작
- Swin Transformer, Microsoft Research
- 업스트림 라이선스
- MIT
- LibreYOLO 코드
- MIT
- 가중치
- MIT, huggingface.co/LibreYOLO에 다시 게시됨
- 해석
- MIT is a permissive license, so these weights can be used in commercial and closed-source products. It asks only that you keep the license text and copyright notice with any copy you redistribute, and it carries no explicit patent grant. LibreYOLO's runtime code for this family is a derived port of the Apache-2.0 timm Swin implementation (Ross Wightman, huggingface/pytorch-image-models), kept parameter-name compatible so the tensors load unchanged; the four released Tiny/Small/Base/Large checkpoints are Microsoft's own MIT-licensed patch-4/window-7 classifiers. Code and weights therefore sit under two different permissive licenses, both of which allow commercial use.
인용
@inproceedings{liu2021Swin,
title={Swin Transformer: Hierarchical Vision Transformer using Shifted Windows},
author={Liu, Ze and Lin, Yutong and Cao, Yue and Hu, Han and Wei, Yixuan and Zhang, Zheng and Lin, Stephen and Guo, Baining},
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
year={2021}
}github.com/microsoft/Swin-Transformer#citing-swin-transformer에 있는 저자의 인용 블록에서 복사했습니다.