v0.42.0
Browse filesSee https://github.com/quic/ai-hub-models/releases/v0.42.0 for changelog.
Files changed (7)
- .gitattributes+2
- DEPLOYMENT_MODEL_LICENSE.pdfAdded+3
- LICENSEAdded+2
- README.mdAdded+254
- SwinV2-Base_float.dlcAdded+3
- SwinV2-Base_float.tfliteAdded+3
- tool-versions.yamlAdded+3
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines333435363732 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textDEPLOYMENT_MODEL_LICENSE.pdf filter=lfs diff=lfs merge=lfs -textSwinV2-Base_float.dlc filter=lfs diff=lfs merge=lfs -text
123version https://git-lfs.github.com/spec/v1oid sha256:4409f93b0e82531303b3e10f52f1fdfb56467a25f05b7441c6bbd8bb8a64b42csize 10962912The license of the original trained model can be found at https://github.com/pytorch/vision/blob/main/LICENSE.The license for the deployable model files (.tflite, .onnx, .dlc, .bin, etc.) can be found in DEPLOYMENT_MODEL_LICENSE.pdf.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254---library_name: pytorchlicense: othertags:- backbone- androidpipeline_tag: image-classification
---

# SwinV2-Base: Optimized for Mobile Deployment## Imagenet classifier and general purpose backbone
SwinV2Base is a machine learning model that can classify images from the Imagenet dataset. It can also be used as a backbone in building more complex models for specific use cases.
This model is an implementation of SwinV2-Base found [here](https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py).
This repository provides scripts to run SwinV2-Base on Qualcomm® devices.More details on model performance across various devices, can be found[here](https://aihub.qualcomm.com/models/swinv2_base).
### Model Details
- **Model Type:** Model_use_case.image_classification- **Model Stats:** - Model checkpoint: Imagenet - Input resolution: 256x256 - Number of parameters: 88.8M - Model size (float): 339 MB - Model size (w8a16): 90.2 MB
| Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model|---|---|---|---|---|---|---|---|---|| SwinV2-Base | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 85.729 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 69.336 ms | 1 - 378 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 43.52 ms | 0 - 503 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 39.262 ms | 1 - 368 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 37.263 ms | 0 - 36 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 28.244 ms | 0 - 53 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 41.214 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 144.249 ms | 1 - 407 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 85.729 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | SA7255P ADP | Qualcomm® SA7255P | QNN_DLC | 69.336 ms | 1 - 378 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 37.27 ms | 0 - 31 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_DLC | 28.125 ms | 0 - 37 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 49.6 ms | 0 - 376 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | SA8295P ADP | Qualcomm® SA8295P | QNN_DLC | 38.959 ms | 1 - 368 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 37.581 ms | 0 - 34 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_DLC | 28.012 ms | 0 - 58 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 41.214 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | SA8775P ADP | Qualcomm® SA8775P | QNN_DLC | 144.249 ms | 1 - 407 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 25.758 ms | 0 - 396 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 19.517 ms | 0 - 380 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 21.025 ms | 0 - 391 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 15.165 ms | 0 - 378 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | TFLITE | 18.056 ms | 0 - 390 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) || SwinV2-Base | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_DLC | 11.895 ms | 1 - 389 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) || SwinV2-Base | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 29.222 ms | 1033 - 1033 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
## Installation
Install the package via pip:```bashpip install qai-hub-models```
## Configure Qualcomm® AI Hub Workbench to run this model on a cloud-hosted device
Sign-in to [Qualcomm® AI Hub Workbench](https://workbench.aihub.qualcomm.com/) with yourQualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
With this API token, you can configure your client to run models on the cloudhosted devices.```bashqai-hub configure --api_token API_TOKEN```Navigate to [docs](https://workbench.aihub.qualcomm.com/docs/) for more information.
## Demo off target
The package contains a simple end-to-end demo that downloads pre-trainedweights and runs this model on a sample input.
```bashpython -m qai_hub_models.models.swinv2_base.demo```
The above demo runs a reference implementation of pre-processing, modelinference, and post processing.
**NOTE**: If you want running in a Jupyter Notebook or Google Colab likeenvironment, please add the following to your cell (instead of the above).```%run -m qai_hub_models.models.swinv2_base.demo```
### Run model on a cloud-hosted device
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®device. This script does the following:* Performance check on-device on a cloud-hosted device* Downloads compiled assets that can be deployed on-device for Android.* Accuracy check between PyTorch and on-device outputs.
```bashpython -m qai_hub_models.models.swinv2_base.export```
## How does this work?
This [export script](https://aihub.qualcomm.com/models/swinv2_base/qai_hub_models/models/SwinV2-Base/export.py)leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this modelon-device. Lets go through each step below in detail:
Step 1: **Compile model for on-device deployment**
To compile a PyTorch model for on-device deployment, we first trace the modelin memory using the `jit.trace` and then call the `submit_compile_job` API.
```pythonimport torch
import qai_hub as hubfrom qai_hub_models.models.swinv2_base import Model
# Load the modeltorch_model = Model.from_pretrained()
# Devicedevice = hub.Device("Samsung Galaxy S25")
# Trace modelinput_shape = torch_model.get_input_spec()sample_inputs = torch_model.sample_inputs()
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
# Compile model on a specific devicecompile_job = hub.submit_compile_job( model=pt_model, device=device, input_specs=torch_model.get_input_spec(),)
# Get target model to run on-devicetarget_model = compile_job.get_target_model()
```
Step 2: **Performance profiling on cloud-hosted device**
After compiling models from step 1. Models can be profiled model on-device using the`target_model`. Note that this scripts runs the model on a device automaticallyprovisioned in the cloud. Once the job is submitted, you can navigate to aprovided job URL to view a variety of on-device performance metrics.```pythonprofile_job = hub.submit_profile_job( model=target_model, device=device,) ```
Step 3: **Verify on-device accuracy**
To verify the accuracy of the model on-device, you can run on-device inferenceon sample input data on the same cloud hosted device.```pythoninput_data = torch_model.sample_inputs()inference_job = hub.submit_inference_job( model=target_model, device=device, inputs=input_data,) on_device_output = inference_job.download_output_data()
```With the output of the model, you can compute like PSNR, relative errors orspot check the output with expected output.
**Note**: This on-device profiling and inference requires access to Qualcomm®AI Hub Workbench. [Sign up for access](https://myaccount.qualcomm.com/signup).
## Run demo on a cloud-hosted device
You can also run the demo on-device.
```bashpython -m qai_hub_models.models.swinv2_base.demo --eval-mode on-device```
**NOTE**: If you want running in a Jupyter Notebook or Google Colab likeenvironment, please add the following to your cell (instead of the above).```%run -m qai_hub_models.models.swinv2_base.demo -- --eval-mode on-device```
## Deploying compiled model to Android
The models can be deployed using multiple runtimes:- TensorFlow Lite (`.tflite` export): [This tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a guide to deploy the .tflite model in an Android application.
- QNN (`.so` export ): This [sample app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)provides instructions on how to use the `.so` shared library in an Android application.
## View on Qualcomm® AI HubGet more details on SwinV2-Base's performance across various devices [here](https://aihub.qualcomm.com/models/swinv2_base).Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
## License* The license for the original implementation of SwinV2-Base can be found [here](https://github.com/pytorch/vision/blob/main/LICENSE).* The license for the compiled assets for on-device deployment can be found [here](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/Qualcomm+AI+Hub+Proprietary+License.pdf)
## References* [Swin Transformer V2: Scaling Up Capacity and Resolution](https://arxiv.org/abs/2111.09883)* [Source Model Implementation](https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py)
## Community* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.* For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
123version https://git-lfs.github.com/spec/v1oid sha256:91a3c1908cfd7bd91e6fb2e1be6d327fc755045f7fddf5560a7e09889dd3b582size 359463044123version https://git-lfs.github.com/spec/v1oid sha256:413a52eff1da1c1a7b2815310ea8439c77154c4b754c2b31f953f635382dee70size 361828916123tool_versions: qnn_dlc: qairt: 2.40.0.251030114326_189385.gitattributes+2
DEPLOYMENT_MODEL_LICENSE.pdfAdded+3
LICENSEAdded+2
README.mdAdded+254
SwinV2-Base_float.dlcAdded+3
SwinV2-Base_float.tfliteAdded+3
tool-versions.yamlAdded+3