3.6 KiB
Task 05: Image Classification Using Python
Task Title
Image Classification Using Python
Description
Implement and test the 05_classification.py script on the Jetson Orin Nano. Runs YOLO26n-cls to give one label for the WHOLE frame (top predictions with probabilities from the 1000 ImageNet classes). No boxes are drawn.
When to Use
Use this when the image contains one main subject and you only need to know what it is, for example sorting products or identifying a held object.
Hardware and Software
- Device: NVIDIA Jetson Orin Nano (JetPack with CUDA and TensorRT)
- Camera: USB webcam (for example Logitech BRIO 100) at CAMERA_INDEX 0
- Language: Python 3
- Model: YOLO26 (Ultralytics), weights
yolo26n-cls.pt - Libraries: ultralytics, opencv-python, numpy
Installation
pip install ultralytics opencv-python
On Jetson, install the JetPack-matched PyTorch and torchvision builds first (see the Ultralytics Jetson guide in the references). Model weights download automatically on first run if the machine is online.
Command to Run
python3 05_classification.py
Check the camera is visible before running:
ls /dev/video*
How It Works
- Load the classification weights (yolo26n-cls.pt).
- Open the camera feed.
- Run the model on each frame.
- Read the top-1 (and top-5) class names and probabilities.
- Overlay the label, probability and FPS. Press Q to quit.
Settings You Can Change
Edit these values at the top of the script:
- CAMERA_INDEX, FRAME_W, FRAME_H : camera options
- Top-K predictions shown
- MODEL_WEIGHTS = yolo26n-cls.pt
- Input size, normally 224
Controls
- Press
Qto quit the live window
Verify the Output
Run python3 05_classification.py and confirm:
- A live window opens with a class label and probability at the top.
- The label changes when you show a different object to the camera.
- No bounding boxes appear; Q closes the window.
Optional: Faster Inference with TensorRT
For higher FPS on the Orin Nano, export the model to a TensorRT engine once and point MODEL_WEIGHTS to the engine file:
yolo export model=yolo26n-cls.pt format=engine half=True
Then set MODEL_WEIGHTS = 'yolo26n-cls.engine' in the script.
Troubleshooting
- Camera not opening: check
ls /dev/video*, try CAMERA_INDEX 1, and make sure no other app is using the camera. - Window does not show over SSH: run on the Jetson desktop, or use X11 forwarding.
- Low FPS: use the nano model, lower FRAME_W / FRAME_H, run
sudo nvpmodel -m 0andsudo jetson_clocks, or export to TensorRT. - Weights not found: connect to the internet for the first run or copy the .pt file next to the script.
- Out of memory: close other apps and reduce the input size.
How This Differs From the Other Tasks
Labels the whole frame with one class, no boxes at all.
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.