Files
Project_documents/Wristwatch_Detection.md
2026-11-23 11:42:41 +05:30

13 KiB
Raw Permalink Blame History

Wristwatch Detection with YOLO26 on NVIDIA Jetson

End-to-end documentation: dataset creation, training, export and Jetson deployment.

Items marked [ ... ] are still to be filled in. Screenshot notes are marked with 📷.

1. Project Overview

This project develops a custom YOLO26 model to detect wristwatches in images and video streams. A dedicated wristwatch dataset is used to train and evaluate the model. The trained model is deployed on an NVIDIA Jetson Orin Nano for real-time detection using GPU acceleration (TensorRT).

1.1 Objectives

  • Build a custom wristwatch dataset with bounding-box annotations.
  • Train and evaluate a YOLO26 detection model.
  • Export the model to ONNX and then to a TensorRT engine.
  • Run real-time detection and tracking on a Jetson using a live camera.

1.2 Pipeline at a Glance

Stage Input Output Where it runs
1. Dataset creation Raw images / video frames Annotated dataset (YOLO format) PC
2. Training Dataset + pretrained YOLO26 best.pt (renamed watch_best.pt) Google Colab (GPU)
3. Evaluation Validation set mAP, precision, recall, curves Google Colab
4. Export watch_best.pt watch_best.onnx Jetson (script)
5. Optimization ONNX / .pt watch_best.engine (TensorRT) Jetson (script)
6. Inference Live camera / video Real-time detections Jetson

2. Hardware and Software Requirements

2.1 Hardware

  • NVIDIA Jetson Orin Nano (inference device)
  • USB camera (e.g. Logitech BRIO 100)
  • Development PC / laptop with internet access

2.2 Software

Component Details
Model YOLO26 (Ultralytics)
Training platform Google Colab with GPU runtime
Annotation tool [ e.g., Roboflow / LabelImg / CVAT ]
Export formats ONNX, TensorRT (.engine)
Jetson OS JetPack [ version ]
Languages / libraries Python 3, Ultralytics, OpenCV, PyTorch

3. Project Structure

The project lives on the Jetson at:

/home/jetson/projects_2026/Watch/Watch_detection
├── watch_detection.py               # detection script + ONNX/TensorRT export
├── watch_tracking.py                # tracking script (ByteTrack)
├── README.md
└── models/
    ├── watch_best.pt                # trained weights (you provide this)
    ├── watch_best.onnx              # generated by the export step
    └── watch_best.engine            # generated by the export step
File Purpose
watch_detection.py Real-time wristwatch detection; also exports ONNX and the TensorRT engine
watch_tracking.py Wristwatch tracking with persistent IDs (ByteTrack)
models/watch_best.pt Best trained YOLO26 weights
models/watch_best.onnx Weights exported to ONNX
models/watch_best.engine TensorRT engine built on the Jetson, loaded automatically at inference

4. Step 1 – Dataset Creation

4.1 Collect Images

  1. Capture images and video of wristwatches using the same type of camera used in deployment wherever possible.
  2. Vary the conditions so the model generalizes:
    • different watch styles (analog, digital, smartwatch, metal / leather / rubber straps)
    • on the wrist, in different hand poses and arm positions
    • different distances and angles
    • different lighting (bright, dim, shadows, reflections on the glass)
    • different backgrounds and sleeves partially covering the watch
    • partial occlusion and motion blur
  3. If using video, extract frames at a fixed interval:
import cv2, os

video_path = "watch_video.mp4"
out_dir = "raw_images"
os.makedirs(out_dir, exist_ok=True)

cap = cv2.VideoCapture(video_path)
count, saved = 0, 0
while True:
    ok, frame = cap.read()
    if not ok:
        break
    if count % 10 == 0:          # save every 10th frame
        cv2.imwrite(f"{out_dir}/frame_{saved:05d}.jpg", frame)
        saved += 1
    count += 1
cap.release()
print("Saved frames:", saved)

Total images collected: [ ... ]

4.2 Annotate the Images

  1. Upload the images to the annotation tool.
  2. Create the class wristwatch [ confirm class name ].
  3. Draw a tight bounding box around every wristwatch (case + dial; decide whether to include the strap and keep it consistent).
  4. Review the labels and fix any inaccurate boxes.

📷 Screenshot: annotation tool with bounding boxes

4.3 Split the Dataset

The dataset was split into training, validation and test sets in a [ 70 / 20 / 10 ] ratio:

Split Share Images
Train [ 70% ] [ ... ]
Validation [ 20% ] [ ... ]
Test [ 10% ] [ ... ]

4.4 Export in YOLO Format

dataset/
├── images/
│   ├── train/
│   ├── val/
│   └── test/
├── labels/
│   ├── train/
│   ├── val/
│   └── test/
└── data.yaml

Each label file contains one line per object:

<class_id> <x_center> <y_center> <width> <height>     (all values normalized 0–1)

Example data.yaml:

path: /content/dataset
train: images/train
val: images/val
test: images/test

names:
  0: wristwatch

5. Step 2 – Model Training (Google Colab)

5.1 Set Up the Environment

  1. Open Google Colab and select Runtime → Change runtime type → GPU.
  2. Mount Google Drive:
from google.colab import drive
drive.mount('/content/drive')
  1. Install Ultralytics and verify the GPU:
!pip install -U ultralytics
!nvidia-smi
  1. Unzip the dataset:
!unzip -q /content/drive/MyDrive/watch_dataset.zip -d /content/dataset

5.2 Train the YOLO26 Model

from ultralytics import YOLO

model = YOLO("yolo26n.pt")      # [ confirm the size you used: n / s / m ]

results = model.train(
    data="/content/dataset/data.yaml",
    epochs=100,                 # [ your value ]
    imgsz=416,                  # [ your value ]
    batch=16,                   # [ your value ]
    project="/content/drive/MyDrive/watch_runs",
    name="watch_yolo26"
)
Parameter Value used
Base model [ yolo26n.pt ]
Epochs [ ... ]
Image size [ ... ]
Batch size [ ... ]

5.3 Locate the Trained Weights

After training, Ultralytics saves the weights in runs/.../weights/:

  • best.pt – checkpoint with the best validation performance (use this one)
  • last.pt – checkpoint from the final epoch

Rename best.pt to watch_best.pt and copy it to the Jetson models/ folder.

6. Step 3 – Evaluation

6.1 Validate the Model

from ultralytics import YOLO

model = YOLO("/content/drive/MyDrive/watch_yolo_weights/watch_best.pt")
metrics = model.val(data="/content/dataset/data.yaml")

print("mAP50    :", metrics.box.map50)
print("mAP50-95 :", metrics.box.map)
print("Precision:", metrics.box.mp)
print("Recall   :", metrics.box.mr)

6.2 Results

Metric Value
Precision [ ... ]
Recall [ ... ]
mAP@50 [ ... ]
mAP@50-95 [ ... ]

📷 Screenshots: results.png, confusion matrix, PR curve

6.3 Test on Sample Images

results = model.predict(source="/content/dataset/images/test", conf=0.5, save=True)

7. Step 4 – Jetson Setup

7.1 Prepare the Jetson

  1. Flash JetPack on the Jetson Orin Nano and boot it up.
  2. Connect the USB camera and confirm it is detected:
ls /dev/video*
  1. Create the project folder and a virtual environment (system site-packages keeps NVIDIA's Jetson PyTorch / TensorRT):
mkdir -p /home/jetson/projects_2026/Watch/Watch_detection/models
cd /home/jetson/projects_2026/Watch/Watch_detection
python3 -m venv --system-site-packages venv
source venv/bin/activate
  1. Install dependencies (use the PyTorch / Ultralytics versions compatible with your JetPack):
pip3 install ultralytics
  1. (Optional) Maximize performance:
sudo nvpmodel -m 0
sudo jetson_clocks

7.2 Copy the Project Files

Copy watch_detection.py, watch_tracking.py and your watch_best.pt into place:

cd /home/jetson/projects_2026/Watch/Watch_detection
ls
ls models        # should contain watch_best.pt

8. Step 5 – Convert watch_best.pt → ONNX → TensorRT Engine

TensorRT converts the model into an engine optimized for the Jetson GPU, giving much faster inference than the plain .pt model. The script handles the whole conversion.

8.1 One command: ONNX + TensorRT engine

cd /home/jetson/projects_2026/Watch/Watch_detection
source venv/bin/activate
python3 watch_detection.py --export-tensorrt --imgsz 416

This runs two steps and produces, in models/:

  • watch_best.onnx
  • watch_best.engine (FP16 by default)

Engine building on the Orin Nano can take several minutes. That is normal.

8.2 Optional variants

# ONNX only
python3 watch_detection.py --export-onnx --imgsz 416

# FP32 engine
python3 watch_detection.py --export-tensorrt --imgsz 416 --quantize 32

# INT8 engine (needs calibration images listed in your data.yaml)
python3 watch_detection.py --export-tensorrt --imgsz 416 --quantize 8 --data /path/to/data.yaml

Notes

  • A TensorRT engine is specific to the device and TensorRT version it was built on. Always build it on the Jetson itself.
  • The export --imgsz must match the --imgsz used at inference (and ideally the training size).
  • If you export ONNX on Colab instead, use model.export(format="onnx", imgsz=416).

📷 Screenshot: export finished with .onnx and .engine files listed

9. Step 6 – Real-Time Detection on Jetson

9.1 Run on the Live Camera

python3 watch_detection.py --source 0 --imgsz 416

If models/watch_best.engine exists it is used automatically; otherwise the script falls back to watch_best.pt.

Other sources:

python3 watch_detection.py --source video.mp4 --save out.mp4       # video file
python3 watch_detection.py --source ./test_images --save-dir ./results   # folder of images
python3 watch_detection.py --source csi                            # CSI camera
python3 watch_detection.py --source 0 --no-display                 # headless / SSH
python3 watch_detection.py --source 0 --debug --conf 0.3           # print all candidate boxes

📷 Screenshot: live detection window with bounding boxes and confidence scores

9.2 Monitor GPU Usage

sudo tegrastats

9.3 Performance

Item Value
Device Jetson Orin Nano
Camera [ ... ]
Input size 416 × 416
Model format TensorRT (.engine, FP16)
FPS [ ... ]

10. Step 7 – Wristwatch Tracking

Tracking assigns a persistent ID to each watch across frames using the Ultralytics .track() function with ByteTrack.

python3 watch_tracking.py --source 0 --imgsz 416
python3 watch_tracking.py --source video.mp4 --save tracked.mp4
python3 watch_tracking.py --source 0 --tracker botsort.yaml    # alternative tracker

The same TensorRT engine is loaded automatically.

📷 Screenshot: tracking output with IDs on the watches

11. Troubleshooting

Problem Possible cause Fix
Camera not opening Wrong index or device busy Check ls /dev/video*, try --source 1, close other apps using the camera
Engine fails to load Built on a different device / TensorRT version Rebuild the engine on the Jetson
Export fails with missing onnx packages Dependencies not installed in the venv pip3 install onnx onnxslim and retry
Low FPS Running .pt instead of .engine, or low power mode Export the engine, run nvpmodel -m 0 and jetson_clocks
Detections missing Size mismatch or threshold too high Same --imgsz for export and inference; lower --conf (try --debug)
Small / distant watches missed Input resolution too low Re-export and run at larger --imgsz (e.g. 640)
Poor accuracy in the field Dataset lacks real-world variety Add images from deployment conditions and retrain
CUDA is not available warning CPU-only PyTorch wheel installed Install NVIDIA's Jetson-specific PyTorch wheel for your JetPack

12. Conclusion

The project covers the complete workflow of a custom object detection system: dataset creation and annotation, YOLO26 training and evaluation on Google Colab, export to ONNX, TensorRT optimization, and real-time wristwatch detection and tracking on an NVIDIA Jetson Orin Nano. [ Add final metrics and FPS once measured. ]

13. Quick Command Reference

# Go to the project folder
cd /home/jetson/projects_2026/Watch/Watch_detection

# Create the virtual environment (first time only)
python3 -m venv --system-site-packages venv

# Activate it
source venv/bin/activate

# Convert watch_best.pt -> ONNX -> TensorRT engine (on Jetson)
python3 watch_detection.py --export-tensorrt --imgsz 416

# Run live detection
python3 watch_detection.py --source 0 --imgsz 416

# Run tracking
python3 watch_tracking.py --source 0 --imgsz 416

# Monitor GPU
sudo tegrastats