/ai-hub-models

The Qualcomm® AI Hub Models are a collection of state-of-the-art machine learning models optimized for performance (latency, memory etc.) and ready to deploy on Qualcomm® devices.

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Qualcomm® AI Hub Models

Qualcomm® AI Hub Models

The Qualcomm® AI Hub Models are a collection of state-of-the-art machine learning models optimized for performance (latency, memory etc.) and ready to deploy on Qualcomm® devices.

  • Explore models optimized for on-device deployment of vision, speech, text, and genenrative AI.
  • View open-source recipes to quantize, optimize, and deploy these models on-device.
  • Browse through performance metrics captured for these models on several devices.
  • Access the models through Hugging Face.
  • Sign up to run these models on hosted Qualcomm® devices.

Supported runtimes

Supported operating systems:

  • Android 11+

Supported compute units

Supported precision

  • Floating Points: FP16
  • Integer: INT8 (8-bit weight and activation on select models), INT4 (4-bit weight, 16-bit activation on select models)

Supported chipsets

Select supported devices

  • Samsung Galaxy S21 Series, Galaxy S22 Series, Galaxy S23 Series, Galaxy S24 Series
  • Xiaomi 12, 13
  • Google Pixel 3, 4, 5

and many more.

Installation

We currently support Python >=3.8 and <= 3.10. We recommend using a Python virtual environment (miniconda or virtualenv).

You can setup a virtualenv using:

python -m venv qai_hub_models_env && source qai_hub_models_env/bin/activate

Once the environment is setup, you can install the base package using:

pip install qai_hub_models

Some models (e.g. YOLOv7) require additional dependencies. You can install those dependencies automatically using:

pip install "qai_hub_models[yolov7]"

Getting Started

Each model comes with the following set of CLI demos:

  • Locally runnable PyTorch based CLI demo to validate the model off device.
  • On-device CLI demo that produces a model ready for on-device deployment and runs the model on a hosted Qualcomm® device (needs sign up).

All the models produced by these demos are freely available on Hugging Face or through our website. See the individual model readme files (e.g. YOLOv7) for more details.

Local CLI Demo with PyTorch

All models contain CLI demos that run the model in PyTorch locally with sample input. Demos are optimized for code clarity rather than latency, and run exclusively in PyTorch. Optimal model latency can be achieved with model export via Qualcomm® AI Hub.

python -m qai_hub_models.models.yolov7.demo

For additional details on how to use the demo CLI, use the --help option

python -m qai_hub_models.models.yolov7.demo --help

See the model directory below to explore all other models.


Note that most ML use cases require some pre and post-processing that are not part of the model itself. A python reference implementation of this is provided for each model in app.py. Apps load & pre-process model input, run model inference, and post-process model output before returning it to you.

Here is an example of how the PyTorch CLI works for YOLOv7:

from PIL import Image
from qai_hub_models.models.yolov7 import Model as YOLOv7Model
from qai_hub_models.models.yolov7 import App as YOLOv7App
from qai_hub_models.utils.asset_loaders import load_image
from qai_hub_models.models.yolov7.demo import IMAGE_ADDRESS

# Load pre-trained model
torch_model = YOLOv7Model.from_pretrained()

# Load a simple PyTorch based application
app = YOLOv7App(torch_model)
image = load_image(IMAGE_ADDRESS, "yolov7")

# Perform prediction on a sample image
pred_image = app.predict(image)[0]
Image.fromarray(pred_image).show()

CLI demo to run on hosted Qualcomm® devices

Some models contain CLI demos that run the model on a hosted Qualcomm® device using Qualcomm® AI Hub.

To run the model on a hosted device, sign up for access to Qualcomm® AI Hub. Sign-in to Qualcomm® AI Hub with your Qualcomm® ID. Once signed in navigate to Account -> Settings -> API Token.

With this API token, you can configure your client to run models on the cloud hosted devices.

qai-hub configure --api_token API_TOKEN

Navigate to docs for more information.

The on-device CLI demo performs the following:

  • Exports the model for on-device execution.
  • Profiles the model on-device on a cloud hosted Qualcomm® device.
  • Runs the model on-device on a cloud hosted Qualcomm® device and compares accuracy between a local CPU based PyTorch run and the on-device run.
  • Downloads models (and other required assets) that can be deployed on-device in an Android application.
python -m qai_hub_models.models.yolov7.export

Many models may have initialization parameters that allow loading custom weights and checkpoints. See --help for more details

python -m qai_hub_models.models.yolov7.export --help

How does this export script work?

As described above, the script above compiles, optimizes, and runs the model on a cloud hosted Qualcomm® device. The demo uses Qualcomm® AI Hub's Python APIs.

Qualcomm® AI Hub explained

Here is a simplified example of code that can be used to run the entire model on a cloud hosted device:

from typing import Tuple
import torch
import qai_hub as hub
from qai_hub_models.models.yolov7 import Model as YOLOv7Model

# Load YOLOv7 in PyTorch
torch_model = YOLOv7Model.from_pretrained()
torch_model.eval()

# Trace the PyTorch model using one data point of provided sample inputs to
# torch tensor to trace the model.
example_input = [torch.tensor(data[0]) for name, data in torch_model.sample_inputs().items()]
pt_model = torch.jit.trace(torch_model, example_input)

# Select a device
device = hub.Device("Samsung Galaxy S23")

# Compile model for a specific device
compile_job = hub.submit_compile_job(
    model=pt_model,
    device=device,
    input_specs=torch_model.get_input_spec(),
)

# Get target model to run on a cloud hosted device
target_model = compile_job.get_target_model()

# Profile the previously compiled model on a cloud hosted device
profile_job = hub.submit_profile_job(
    model=target_model,
    device=device,
)

# Perform on-device inference on a cloud hosted device
input_data = torch_model.sample_inputs()
inference_job = hub.submit_inference_job(
    model=target_model,
    device=device,
    inputs=input_data,
)

# Returns the output as dict{name: numpy}
on_device_output = inference_job.download_output_data()

Working with source code

You can clone the repository using:

git clone https://github.com/quic/ai-hub-models/blob/main
cd main
pip install -e .

Install additional dependencies to prepare a model before using the following:

cd main
pip install -e ".[yolov7]"

All models have accuracy and end-to-end tests when applicable. These tests as designed to be run locally and verify that the PyTorch code produces correct results. To run the tests for a model:

python -m pytest --pyargs qai_hub_models.models.yolov7.test

For any issues, please contact us at ai-hub-support@qti.qualcomm.com.


Model Directory

Computer Vision

Model README Torch App Device Export CLI Demo
Image Classification
MobileNet-v2-Quantized qai_hub_models.models.mobilenet_v2_quantized ✔️ ✔️ ✔️
GoogLeNet qai_hub_models.models.googlenet ✔️ ✔️ ✔️
ResNet50 qai_hub_models.models.resnet50 ✔️ ✔️ ✔️
Swin-Small qai_hub_models.models.swin_small ✔️ ✔️ ✔️
Inception-v3Quantized qai_hub_models.models.inception_v3_quantized ✔️ ✔️ ✔️
MobileNet-v3-Small qai_hub_models.models.mobilenet_v3_small ✔️ ✔️ ✔️
GoogLeNetQuantized qai_hub_models.models.googlenet_quantized ✔️ ✔️ ✔️
RegNet qai_hub_models.models.regnet ✔️ ✔️ ✔️
ResNeXt50 qai_hub_models.models.resnext50 ✔️ ✔️ ✔️
VIT qai_hub_models.models.vit ✔️ ✔️ ✔️
ResNet18Quantized qai_hub_models.models.resnet18_quantized ✔️ ✔️ ✔️
ResNet101 qai_hub_models.models.resnet101 ✔️ ✔️ ✔️
ResNeXt101 qai_hub_models.models.resnext101 ✔️ ✔️ ✔️
MobileNet-v2 qai_hub_models.models.mobilenet_v2 ✔️ ✔️ ✔️
SqueezeNet-1_1 qai_hub_models.models.squeezenet1_1 ✔️ ✔️ ✔️
SqueezeNet-1_1Quantized qai_hub_models.models.squeezenet1_1_quantized ✔️ ✔️ ✔️
Inception-v3 qai_hub_models.models.inception_v3 ✔️ ✔️ ✔️
WideResNet50 qai_hub_models.models.wideresnet50 ✔️ ✔️ ✔️
ResNet101Quantized qai_hub_models.models.resnet101_quantized ✔️ ✔️ ✔️
MNASNet05 qai_hub_models.models.mnasnet05 ✔️ ✔️ ✔️
Swin-Base qai_hub_models.models.swin_base ✔️ ✔️ ✔️
DenseNet-121 qai_hub_models.models.densenet121 ✔️ ✔️ ✔️
Shufflenet-v2Quantized qai_hub_models.models.shufflenet_v2_quantized ✔️ ✔️ ✔️
Shufflenet-v2 qai_hub_models.models.shufflenet_v2 ✔️ ✔️ ✔️
ResNeXt101Quantized qai_hub_models.models.resnext101_quantized ✔️ ✔️ ✔️
ResNet18 qai_hub_models.models.resnet18 ✔️ ✔️ ✔️
EfficientNet-B0 qai_hub_models.models.efficientnet_b0 ✔️ ✔️ ✔️
MobileNet-v3-Large qai_hub_models.models.mobilenet_v3_large ✔️ ✔️ ✔️
WideResNet50-Quantized qai_hub_models.models.wideresnet50_quantized ✔️ ✔️ ✔️
ConvNext-Tiny qai_hub_models.models.convnext_tiny ✔️ ✔️ ✔️
Swin-Tiny qai_hub_models.models.swin_tiny ✔️ ✔️ ✔️
Image Editing
LaMa-Dilated qai_hub_models.models.lama_dilated ✔️ ✔️ ✔️
Image Generation
StyleGAN2 qai_hub_models.models.stylegan2 ✔️ ✔️ ✔️
Super Resolution
QuickSRNetLarge qai_hub_models.models.quicksrnetlarge ✔️ ✔️ ✔️
ESRGAN qai_hub_models.models.esrgan ✔️ ✔️ ✔️
Real-ESRGAN-x4plus qai_hub_models.models.real_esrgan_x4plus ✔️ ✔️ ✔️
XLSR-Quantized qai_hub_models.models.xlsr_quantized ✔️ ✔️ ✔️
QuickSRNetMedium qai_hub_models.models.quicksrnetmedium ✔️ ✔️ ✔️
Real-ESRGAN-General-x4v3 qai_hub_models.models.real_esrgan_general_x4v3 ✔️ ✔️ ✔️
SESR-M5-Quantized qai_hub_models.models.sesr_m5_quantized ✔️ ✔️ ✔️
QuickSRNetSmall qai_hub_models.models.quicksrnetsmall ✔️ ✔️ ✔️
SESR-M5 qai_hub_models.models.sesr_m5 ✔️ ✔️ ✔️
XLSR qai_hub_models.models.xlsr ✔️ ✔️ ✔️
Semantic Segmentation
Yolo-v8-Segmentation qai_hub_models.models.yolov8_seg ✔️ ✔️ ✔️
SINet qai_hub_models.models.sinet ✔️ ✔️ ✔️
Unet-Segmentation qai_hub_models.models.unet_segmentation ✔️ ✔️ ✔️
FCN_ResNet50 qai_hub_models.models.fcn_resnet50 ✔️ ✔️ ✔️
DDRNet23-Slim qai_hub_models.models.ddrnet23_slim ✔️ ✔️ ✔️
FastSam-S qai_hub_models.models.fastsam_s ✔️ ✔️ ✔️
FFNet-122NS-LowRes qai_hub_models.models.ffnet_122ns_lowres ✔️ ✔️ ✔️
FFNet-78S-Quantized qai_hub_models.models.ffnet_78s_quantized ✔️ ✔️ ✔️
FFNet-40S-Quantized qai_hub_models.models.ffnet_40s_quantized ✔️ ✔️ ✔️
MediaPipe-Selfie-Segmentation qai_hub_models.models.mediapipe_selfie ✔️ ✔️ ✔️
DeepLabV3-ResNet50 qai_hub_models.models.deeplabv3_resnet50 ✔️ ✔️ ✔️
FastSam-X qai_hub_models.models.fastsam_x ✔️ ✔️ ✔️
FFNet-54S qai_hub_models.models.ffnet_54s ✔️ ✔️ ✔️
FFNet-78S-LowRes qai_hub_models.models.ffnet_78s_lowres ✔️ ✔️ ✔️
Segment-Anything-Model qai_hub_models.models.sam ✔️ ✔️ ✔️
FFNet-78S qai_hub_models.models.ffnet_78s ✔️ ✔️ ✔️
FFNet-40S qai_hub_models.models.ffnet_40s ✔️ ✔️ ✔️
FFNet-54S-Quantized qai_hub_models.models.ffnet_54s_quantized ✔️ ✔️ ✔️
Object Detection
MediaPipe-Hand-Detection qai_hub_models.models.mediapipe_hand ✔️ ✔️ ✔️
DETR-ResNet50-DC5 qai_hub_models.models.detr_resnet50_dc5 ✔️ ✔️ ✔️
DETR-ResNet101-DC5 qai_hub_models.models.detr_resnet101_dc5 ✔️ ✔️ ✔️
Yolo-v8-Detection qai_hub_models.models.yolov8_det ✔️ ✔️ ✔️
DETR-ResNet101 qai_hub_models.models.detr_resnet101 ✔️ ✔️ ✔️
DETR-ResNet50 qai_hub_models.models.detr_resnet50 ✔️ ✔️ ✔️
Yolo-v7 qai_hub_models.models.yolov7 ✔️ ✔️ ✔️
Yolo-v6 qai_hub_models.models.yolov6 ✔️ ✔️ ✔️
MediaPipe-Face-Detection qai_hub_models.models.mediapipe_face ✔️ ✔️ ✔️
Pose Estimation
HRNetPoseQuantized qai_hub_models.models.hrnet_pose_quantized ✔️ ✔️ ✔️
MediaPipe-Pose-Estimation qai_hub_models.models.mediapipe_pose ✔️ ✔️ ✔️
LiteHRNet qai_hub_models.models.litehrnet ✔️ ✔️ ✔️
HRNetPose qai_hub_models.models.hrnet_pose ✔️ ✔️ ✔️
OpenPose qai_hub_models.models.openpose ✔️ ✔️ ✔️

Audio

Model README Torch App Device Export CLI Demo
Speech Recognition
Whisper-Base qai_hub_models.models.whisper_asr ✔️ ✔️ ✔️
HuggingFace-WavLM-Base-Plus qai_hub_models.models.huggingface_wavlm_base_plus ✔️ ✔️ ✔️
Audio Enhancement
Facebook-Denoiser qai_hub_models.models.facebook_denoiser ✔️ ✔️ ✔️

Multimodal

Model README Torch App Device Export CLI Demo
TrOCR qai_hub_models.models.trocr ✔️ ✔️ ✔️
OpenAI-Clip qai_hub_models.models.openai_clip ✔️ ✔️ ✔️

Generative Ai

Model README Torch App Device Export CLI Demo
Image Generation
Stable-Diffusion qai_hub_models.models.stable_diffusion_quantized ✔️ ✔️ ✔️
ControlNet qai_hub_models.models.controlnet_quantized ✔️ ✔️ ✔️
Text Generation
Llama-v2-7B-Chat qai_hub_models.models.llama_v2_7b_chat_quantized ✔️ ✔️ ✔️
Baichuan-7B qai_hub_models.models.baichuan_7b_quantized ✔️ ✔️ ✔️