• bitcoinBitcoin(BTC)$78,730.00-0.66%
  • ethereumEthereum(ETH)$2,493.560.04%
  • tetherTether(USDT)$1.000.00%
  • binancecoinBNB(BNB)$752.581.73%
  • rippleXRP(XRP)$1.421.38%
  • usd-coinUSDC(USDC)$1.000.01%
  • solanaSolana(SOL)$103.65-0.26%
  • tronTRON(TRX)$0.3391921.50%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.040.00%
  • zcashZcash(ZEC)$1,184.934.64%
  • HyperliquidHyperliquid(HYPE)$85.600.71%
  • dogecoinDogecoin(DOGE)$0.090328-0.72%
  • RainRain(RAIN)$0.016170-0.83%
  • USDSUSDS(USDS)$1.000.01%
  • whitebitWhiteBIT Coin(WBT)$81.536.42%
  • chainlinkChainlink(LINK)$12.52-2.04%
  • moneroMonero(XMR)$495.43-4.30%
  • leo-tokenLEO Token(LEO)$9.210.14%
  • cardanoCardano(ADA)$0.219853-0.62%
  • stellarStellar(XLM)$0.188040-2.55%
  • bitcoin-cashBitcoin Cash(BCH)$257.83-1.66%
  • daiDai(DAI)$1.00-0.01%
  • Ethena USDeEthena USDe(USDE)$1.000.01%
  • USD1USD1(USD1)$1.000.00%
  • CantonCanton(CC)$0.1081001.87%
  • uniswapUniswap(UNI)$6.76-2.14%
  • litecoinLitecoin(LTC)$54.26-2.39%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.400.64%
  • hedera-hashgraphHedera(HBAR)$0.078841-4.35%
  • avalanche-2Avalanche(AVAX)$7.99-1.40%
  • suiSui(SUI)$0.81-1.26%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • shiba-inuShiba Inu(SHIB)$0.000005-1.18%
  • crypto-com-chainCronos(CRO)$0.06332110.82%
  • nearNEAR Protocol(NEAR)$2.34-0.37%
  • paypal-usdPayPal USD(PYUSD)$1.000.01%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • MemeCoreMemeCore(M)$1.213.98%
  • tether-goldTether Gold(XAUT)$4,355.74-1.32%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • BittensorBittensor(TAO)$258.06-1.31%
  • Ripple USDRipple USD(RLUSD)$1.000.00%
  • okbOKB(OKB)$113.66-3.55%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.35%
  • mantleMantle(MNT)$0.631.27%
  • polkadotPolkadot(DOT)$1.2113.77%
  • AsterAster(ASTER)$0.75-2.62%
  • aaveAave(AAVE)$129.19-2.21%
  • pax-goldPAX Gold(PAXG)$4,361.06-1.33%
  • Pump.funPump.fun(PUMP)$0.004402-1.47%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

A Hands-On Coding Tutorial on Qualcomm AI Hub Models for Classification, Object Detection, and Hardware-Aware Deployment

June 5, 2026
in AI & Technology
Reading Time: 7 mins read
A A
A Hands-On Coding Tutorial on Qualcomm AI Hub Models for Classification, Object Detection, and Hardware-Aware Deployment
ShareShareShareShareShare

In this tutorial, we work through an end-to-end workflow for Qualcomm AI Hub Models. We start by setting up the required package, discovering the available model collection, and loading MobileNet-V2 for local PyTorch inference. We also handle an important input-shape issue by converting NHWC image tensors into the NCHW format expected by the model. From there, we run inference on both the model’s built-in sample input and a real image, inspect top predictions, execute the official Qualcomm AI Hub CLI demo, and extend the workflow with a YOLOv7 object detection example. Also, we include an optional cloud-device section where we compile, profile, and run the model on a real Qualcomm device when an API token is available.

Copy CodeCopiedUse a different Browser
import subprocess, sys, os, glob, textwrap, traceback
import numpy as np, torch
from PIL import Image
import matplotlib.pyplot as plt
def pip_install(*pkgs):
   subprocess.run([sys.executable, "-m", "pip", "install", "-q", *pkgs], check=True)
pip_install("qai_hub_models")
OUT_DIR = "/content/qaihm_out"; os.makedirs(OUT_DIR, exist_ok=True)
torch.set_grad_enabled(False)
def to_nchw(value):
   arr = value[0] if isinstance(value, (list, tuple)) else value
   t = torch.from_numpy(np.asarray(arr, dtype=np.float32))
   if t.ndim == 3:
       t = t.unsqueeze(0)
   if t.ndim == 4 and t.shape[1] != 3 and t.shape[-1] == 3:
       t = t.permute(0, 3, 1, 2).contiguous()
   return t

We begin by importing libraries and setting up a helper function to install packages directly inside Colab. We install qai_hub_models, create an output directory, and disable gradient tracking since we only need inference. We also define the to_nchw() function to convert any input image tensor to the channel-first format expected by the model.

Copy CodeCopiedUse a different Browser
import pkgutil, qai_hub_models.models as _m
model_ids = sorted(n for _, n, p in pkgutil.iter_modules(_m.__path__)
                  if p and not n.startswith("_"))
print(f">>> {len(model_ids)} models available. First 40:\n")
print(textwrap.fill(", ".join(model_ids[:40]), 100), "\n")
from qai_hub_models.models.mobilenet_v2 import Model as MobileNetV2
model = MobileNetV2.from_pretrained().eval()
spec = model.get_input_spec()
input_name = list(spec.keys())[0]
print(">>> Input:", input_name, spec[input_name].shape, spec[input_name].dtype)
from torchvision.models import MobileNet_V2_Weights
IMAGENET_CLASSES = MobileNet_V2_Weights.IMAGENET1K_V1.meta["categories"]
def top5(logits):
   if logits.ndim == 1: logits = logits.unsqueeze(0)
   probs = torch.softmax(logits, dim=1)[0]
   conf, idx = probs.topk(5)
   return [(IMAGENET_CLASSES[i], float(c)) for c, i in zip(conf, idx)]

We discover the available Qualcomm AI Hub model packages and print the first set of model IDs to understand what is accessible. We then load the pretrained MobileNet-V2 model, read its input specification, and identify the correct input name. We also prepare the ImageNet class labels and define a top5() function to convert model logits into readable top-5 predictions.

Copy CodeCopiedUse a different Browser
sample = model.sample_inputs()
x = to_nchw(sample[input_name])
print(">>> fed tensor shape:", tuple(x.shape))
print("\n>>> Top-5 for the built-in sample input:")
for label, conf in top5(model(x)):
   print(f"    {conf:6.2%}  {label}")
from torchvision import transforms
preprocess = transforms.Compose([
   transforms.Resize(256), transforms.CenterCrop(224), transforms.ToTensor(),
])
img = None
try:
   import urllib.request
   p = os.path.join(OUT_DIR, "input.jpg")
   urllib.request.urlretrieve(
       "https://raw.githubusercontent.com/pytorch/hub/master/images/dog.jpg", p)
   img = Image.open(p).convert("RGB")
except Exception as e:
   print(">>> photo download skipped:", e)
if img is not None:
   preds = top5(model(preprocess(img).unsqueeze(0)))
   print("\n>>> Top-5 for the downloaded photo:")
   for label, conf in preds: print(f"    {conf:6.2%}  {label}")
   plt.figure(figsize=(5,5)); plt.imshow(img); plt.axis("off")
   plt.title(f"{preds[0][0]}  ({preds[0][1]:.1%})"); plt.show()

We first run inference using the model’s built-in sample input and use to_nchw() to fix the tensor shape before passing it to MobileNet-V2. We then download a real image, preprocess it using standard resizing, cropping, and tensor conversion steps, and run another prediction. We finally display the image with the top predicted label to visually connect the model output to the input photo.

Copy CodeCopiedUse a different Browser
def run_demo(module, extra=None, timeout=900):
   cmd = [sys.executable, "-m", module, "--eval-mode", "fp",
          "--output-dir", OUT_DIR] + (extra or [])
   print(f"\n>>> {' '.join(cmd)}")
   try:
       r = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
       print("\n".join((r.stdout + r.stderr).strip().splitlines()[-25:]))
   except Exception as e:
       print(">>> demo skipped:", e)
run_demo("qai_hub_models.models.mobilenet_v2.demo")
try:
   pip_install("qai_hub_models[yolov7]")
   run_demo("qai_hub_models.models.yolov7.demo")
   imgs = sorted(glob.glob(OUT_DIR + "/*.png") + glob.glob(OUT_DIR + "/*.jpg"),
                 key=os.path.getmtime)
   if imgs:
       plt.figure(figsize=(9,9)); plt.imshow(Image.open(imgs[-1]).convert("RGB"))
       plt.axis("off"); plt.title("YOLOv7 detections"); plt.show()
   else:
       print(">>> no output image found (results may have printed instead).")
except Exception:
   print(">>> YOLOv7 section skipped:\n", traceback.format_exc())

We define a reusable run_demo() function that executes official Qualcomm AI Hub model demos from the command line. We use it to run the MobileNet-V2 demo and then install the YOLOv7 extras for object detection. We run the YOLOv7 demo, search for the generated output image, and visualize the detections if an image is created.

Copy CodeCopiedUse a different Browser
try:
   import qai_hub as hub
   devices = hub.get_devices()
   print(f"\n>>> Authenticated. {len(devices)} cloud devices available.")
   device = hub.Device("Samsung Galaxy S24 (Family)")
   sample = model.sample_inputs()
   nchw = to_nchw(sample[input_name])
   traced = torch.jit.trace(model, [nchw])
   cloud_inputs = {input_name: [nchw.numpy()]}
   cj = hub.submit_compile_job(model=traced, device=device,
                               input_specs=model.get_input_spec(),
                               options="--target_runtime tflite")
   target = cj.get_target_model(); print(">>> compiled:", cj.url)
   pj = hub.submit_profile_job(model=target, device=device); print(">>> profiling:", pj.url)
   ij = hub.submit_inference_job(model=target, device=device, inputs=cloud_inputs)
   out = ij.download_output_data()
   dev_logits = torch.from_numpy(np.asarray(list(out.values())[0][0]))
   print(">>> Top-5 from the REAL device:")
   for label, conf in top5(dev_logits): print(f"    {conf:6.2%}  {label}")
   target.download(os.path.join(OUT_DIR, "mobilenet_v2.tflite"))
   print(">>> saved compiled .tflite to", OUT_DIR)
except Exception as e:
   print("\n>>> Cloud (on-device) section skipped — no API token configured.")
   print("    Get one at workbench.aihub.qualcomm.com, then:")
   print("    !qai-hub configure --api_token YOUR_TOKEN")
   print("    detail:", (str(e).splitlines() or [type(e).__name__])[0])
print("\n>>> Tutorial complete. Outputs in:", OUT_DIR)

We include an optional Qualcomm AI Hub cloud workflow that runs only when an API token is configured. We retrieve available cloud devices, trace the PyTorch model, compile it for TFLite, profile it on a Qualcomm device, and submit an inference job. We then download the device output, print the top predictions, save the compiled TFLite model, and finish by showing where all tutorial outputs are stored.

In conclusion, we have a complete practical workflow for using Qualcomm AI Hub Models inside Colab. We learned how to load pretrained models, prepare inputs correctly, run local inference, visualize classification and detection results, and use the official demos as reproducible reference points. We also saw how the same model can move beyond local PyTorch execution into Qualcomm’s cloud-device pipeline for compilation, profiling, and real-device inference. It provides a path from simple experimentation to hardware-aware deployment with Qualcomm AI Hub.


Check out the Full Codes with Notebook here. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us

YOU MAY ALSO LIKE

Sierra Open-Sources Hyper-τ-Bench, a Benchmark for Agent Construction

SpaceX’s Recovered Starship 40 Will Take Months To Get Back To Texas

The post A Hands-On Coding Tutorial on Qualcomm AI Hub Models for Classification, Object Detection, and Hardware-Aware Deployment appeared first on MarkTechPost.

Credit: Source link

ShareTweetSendSharePin

Related Posts

Sierra Open-Sources Hyper-τ-Bench, a Benchmark for Agent Construction
AI & Technology

Sierra Open-Sources Hyper-τ-Bench, a Benchmark for Agent Construction

September 8, 2026
SpaceX’s Recovered Starship 40 Will Take Months To Get Back To Texas
AI & Technology

SpaceX’s Recovered Starship 40 Will Take Months To Get Back To Texas

September 8, 2026
What Is Roku’s Secret Menu And How Do You Unlock It?
AI & Technology

What Is Roku’s Secret Menu And How Do You Unlock It?

September 8, 2026
NVIDIA Announces CUDA Rust with cuda-oxide (SIMT) and cutile-rs (Tile) for Compile-Time-Safe GPU Kernels
AI & Technology

NVIDIA Announces CUDA Rust with cuda-oxide (SIMT) and cutile-rs (Tile) for Compile-Time-Safe GPU Kernels

September 8, 2026
Next Post
Elon Musk outlines bold vision for SpaceX, goes light on details at JPMorgan event touting historic IPO

Elon Musk outlines bold vision for SpaceX, goes light on details at JPMorgan event touting historic IPO

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Harbour Energy: The Bargain Persists With An Enhanced Share Buyback Program (PMOIF)

Harbour Energy: The Bargain Persists With An Enhanced Share Buyback Program (PMOIF)

September 8, 2026
Divers clean famous underwater statue off Italian coast

Divers clean famous underwater statue off Italian coast

September 6, 2026
Trump attends dignified transfer for four U.S. service members killed in Iran War

Trump attends dignified transfer for four U.S. service members killed in Iran War

September 7, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!