initial commit
This commit is contained in:
@@ -0,0 +1,107 @@
|
|||||||
|
# Task 01: Object Detection Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Object Detection Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `01_detection.py` script on the Jetson Orin Nano. Opens a camera feed, runs YOLO26n object detection on every frame and draws a bounding box, class name and confidence for each object (80 COCO classes). Live FPS and object count are shown on screen.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this when you only need to know WHAT is in the frame and WHERE (as a box). It does not track objects across frames, give pixel-exact shapes, or find body joints.
|
||||||
|
|
||||||
|
## 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.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 01_detection.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the YOLO26n model once and run a warm-up pass on a dummy image so the first real frame is not slow.
|
||||||
|
2. Open the camera with OpenCV and set the resolution (1280x720).
|
||||||
|
3. For every frame call the model with the confidence and IoU thresholds.
|
||||||
|
4. Read boxes, class ids and confidences from the result and draw them with OpenCV.
|
||||||
|
5. Compute and overlay FPS and the number of detected objects. Press Q to quit.
|
||||||
|
|
||||||
|
## Settings You Can Change
|
||||||
|
|
||||||
|
Edit these values at the top of the script:
|
||||||
|
|
||||||
|
- CAMERA_INDEX = 0 : which camera to open (0 = default)
|
||||||
|
- FRAME_W / FRAME_H = 1280 / 720 : capture resolution
|
||||||
|
- CONF_THRESHOLD = 0.45 : ignore detections below this confidence
|
||||||
|
- IOU_THRESHOLD = 0.45 : Non-Max-Suppression threshold that removes duplicate boxes
|
||||||
|
- MODEL_WEIGHTS = yolo26n.pt : nano model, smallest and fastest, good for Jetson
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 01_detection.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] A live window titled 'YOLO - Detection' opens.
|
||||||
|
- [ ] Green boxes with labels like 'person 0.87' appear around objects.
|
||||||
|
- [ ] FPS and Objects counters show at the top-left.
|
||||||
|
- [ ] Pressing Q closes the window cleanly.
|
||||||
|
|
||||||
|
## 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.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n.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 0` and `sudo 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
|
||||||
|
|
||||||
|
02_tracking adds persistent IDs, 03_segmentation gives pixel masks, 04_pose_estimation finds keypoints, 05_classification labels the whole frame.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [Object detection task docs](https://docs.ultralytics.com/tasks/detect/)
|
||||||
|
- [Predict mode docs](https://docs.ultralytics.com/modes/predict/)
|
||||||
|
- [COCO dataset (80 classes)](https://docs.ultralytics.com/datasets/detect/coco/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
# Task 02: Object Tracking Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Object Tracking Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `02_tracking.py` script on the Jetson Orin Nano. Runs YOLO26n detection and then tracks each object across frames, giving every object a persistent ID shown next to its box. Uses the Ultralytics tracking mode (ByteTrack by default).
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this when you need to follow the same object over time, for example counting unique people or vehicles, or measuring how long something stays in view.
|
||||||
|
|
||||||
|
## 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.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 02_tracking.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the YOLO26n model.
|
||||||
|
2. Open the camera feed.
|
||||||
|
3. Call the model's track function on each frame with persist=True so IDs carry over between frames.
|
||||||
|
4. Read boxes, class ids and track IDs from the result and draw them.
|
||||||
|
5. Show FPS and the number of tracked objects. Press Q to quit.
|
||||||
|
|
||||||
|
## Settings You Can Change
|
||||||
|
|
||||||
|
Edit these values at the top of the script:
|
||||||
|
|
||||||
|
- CAMERA_INDEX : which camera to open
|
||||||
|
- FRAME_W / FRAME_H : capture resolution
|
||||||
|
- CONF_THRESHOLD / IOU_THRESHOLD : detection thresholds
|
||||||
|
- TRACKER : tracker config, bytetrack.yaml (fast) or botsort.yaml (more robust)
|
||||||
|
- MODEL_WEIGHTS = yolo26n.pt
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 02_tracking.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] A live tracking window opens.
|
||||||
|
- [ ] Each object has a box with a class name and an ID such as 'id:3 person'.
|
||||||
|
- [ ] The ID stays the same while the object moves around the frame.
|
||||||
|
- [ ] A new object gets a new ID; 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.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n.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 0` and `sudo 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
|
||||||
|
|
||||||
|
Same as 01_detection but with persistent IDs across frames.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Multi-object tracking docs](https://docs.ultralytics.com/modes/track/)
|
||||||
|
- [Tracker comparison (ByteTrack, BoT-SORT)](https://docs.ultralytics.com/modes/track/#available-trackers)
|
||||||
|
- [ByteTrack paper](https://arxiv.org/abs/2110.06864)
|
||||||
|
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# Task 03: Instance Segmentation Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Instance Segmentation Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `03_segmentation.py` script on the Jetson Orin Nano. Runs YOLO26n-seg to find objects and draw their exact pixel outline (mask) in addition to the box, class name and confidence.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this when a rectangle is not precise enough, for example measuring object area, cutting an object out of the background, or separating touching objects.
|
||||||
|
|
||||||
|
## 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-seg.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 03_segmentation.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the segmentation weights (yolo26n-seg.pt).
|
||||||
|
2. Open the camera feed.
|
||||||
|
3. Run the model on each frame.
|
||||||
|
4. Read the masks from the result and overlay them as coloured regions on the frame.
|
||||||
|
5. Draw labels, FPS and object count. 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
|
||||||
|
- CONF_THRESHOLD / IOU_THRESHOLD : detection thresholds
|
||||||
|
- MODEL_WEIGHTS = yolo26n-seg.pt
|
||||||
|
- Mask transparency / colour options, if defined in the script
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 03_segmentation.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] A live window opens with coloured mask overlays on objects.
|
||||||
|
- [ ] Mask edges follow the object shape, not just a rectangle.
|
||||||
|
- [ ] FPS is lower than detection (masks cost more); 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-seg.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n-seg.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 0` and `sudo 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
|
||||||
|
|
||||||
|
Gives pixel-exact outlines, unlike 01_detection which gives boxes only.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Instance segmentation task docs](https://docs.ultralytics.com/tasks/segment/)
|
||||||
|
- [Segmentation models list](https://docs.ultralytics.com/tasks/segment/#models)
|
||||||
|
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [COCO dataset](https://docs.ultralytics.com/datasets/segment/coco/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
# Task 04: Pose Estimation Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Pose Estimation Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `04_pose_estimation.py` script on the Jetson Orin Nano. Runs YOLO26n-pose to detect people and their 17 body keypoints (nose, eyes, ears, shoulders, elbows, wrists, hips, knees, ankles) and draws the skeleton on screen.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this for human activity analysis, fitness or posture checks, gesture-based control, and fall detection.
|
||||||
|
|
||||||
|
## 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-pose.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 04_pose_estimation.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the pose weights (yolo26n-pose.pt).
|
||||||
|
2. Open the camera feed (or an input image or video).
|
||||||
|
3. Run the model on each frame.
|
||||||
|
4. Read keypoints and confidences from the result.
|
||||||
|
5. Draw the keypoints and connecting skeleton lines, plus 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
|
||||||
|
- CONF_THRESHOLD : minimum person confidence
|
||||||
|
- Keypoint confidence limit for drawing a joint, if defined
|
||||||
|
- MODEL_WEIGHTS = yolo26n-pose.pt
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 04_pose_estimation.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] A live window opens and a skeleton is drawn on each person.
|
||||||
|
- [ ] Joints move smoothly with the body.
|
||||||
|
- [ ] Keypoints are visible for the whole body when the person is fully in frame.
|
||||||
|
- [ ] 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-pose.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n-pose.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 0` and `sudo 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
|
||||||
|
|
||||||
|
Finds body joints, whereas 01 to 03 only find objects or shapes.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Pose estimation task docs](https://docs.ultralytics.com/tasks/pose/)
|
||||||
|
- [COCO keypoints dataset](https://docs.ultralytics.com/datasets/pose/coco/)
|
||||||
|
- [Workouts monitoring solution](https://docs.ultralytics.com/guides/workouts-monitoring/)
|
||||||
|
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
1. Load the classification weights (yolo26n-cls.pt).
|
||||||
|
2. Open the camera feed.
|
||||||
|
3. Run the model on each frame.
|
||||||
|
4. Read the top-1 (and top-5) class names and probabilities.
|
||||||
|
5. 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 `Q` to 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 0` and `sudo 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.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Image classification task docs](https://docs.ultralytics.com/tasks/classify/)
|
||||||
|
- [ImageNet dataset](https://docs.ultralytics.com/datasets/classify/imagenet/)
|
||||||
|
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [ImageNet class list](https://github.com/ultralytics/yolov5/blob/master/data/ImageNet.yaml)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
# Task 06: ROI (Region of Interest) Detection Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
ROI (Region of Interest) Detection Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `06_roi_detection.py` script on the Jetson Orin Nano. Runs YOLO26n detection but only reports and counts objects that are inside a user-defined region of interest. The region is drawn on the frame and objects outside it are ignored.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this for zone monitoring, such as counting people at a door, checking a restricted area, or watching one machine or shelf.
|
||||||
|
|
||||||
|
## 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.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 06_roi_detection.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the YOLO26n model.
|
||||||
|
2. Define the ROI (rectangle or polygon) in the script settings.
|
||||||
|
3. Run detection on each frame.
|
||||||
|
4. Check whether each box centre falls inside the ROI.
|
||||||
|
5. Draw only the objects inside the ROI, show the in-zone count and FPS. Press Q to quit.
|
||||||
|
|
||||||
|
## Settings You Can Change
|
||||||
|
|
||||||
|
Edit these values at the top of the script:
|
||||||
|
|
||||||
|
- ROI coordinates (rectangle or polygon points) : the zone to watch
|
||||||
|
- CAMERA_INDEX, FRAME_W, FRAME_H : camera options
|
||||||
|
- CONF_THRESHOLD / IOU_THRESHOLD : detection thresholds
|
||||||
|
- MODEL_WEIGHTS = yolo26n.pt
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 06_roi_detection.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] The ROI outline is visible on the live window.
|
||||||
|
- [ ] Objects inside the ROI get boxes and are counted.
|
||||||
|
- [ ] Objects outside the ROI are not drawn or counted.
|
||||||
|
- [ ] The count updates as objects enter or leave; 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.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n.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 0` and `sudo 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
|
||||||
|
|
||||||
|
Same detector as 01 but limited to a chosen zone.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Object counting in regions](https://docs.ultralytics.com/guides/region-counting/)
|
||||||
|
- [Ultralytics Solutions](https://docs.ultralytics.com/solutions/)
|
||||||
|
- [Object detection task docs](https://docs.ultralytics.com/tasks/detect/)
|
||||||
|
- [OpenCV drawing functions](https://docs.opencv.org/4.x/dc/da5/tutorial_py_drawing_functions.html)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# Task 07: Oriented Bounding Box (OBB) Detection Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Oriented Bounding Box (OBB) Detection Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `07_obb_detection.py` script on the Jetson Orin Nano. Runs YOLO26n-obb to detect objects with rotated bounding boxes that follow the object's angle instead of a straight rectangle.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this for objects that appear at any angle, such as aerial or satellite images, ships, vehicles, parts on a conveyor or tilted text and tools.
|
||||||
|
|
||||||
|
## 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-obb.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 07_obb_detection.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the OBB weights (yolo26n-obb.pt).
|
||||||
|
2. Open the camera feed or an input image or video.
|
||||||
|
3. Run the model on each frame.
|
||||||
|
4. Read the rotated box corners, class and confidence from the result.
|
||||||
|
5. Draw the rotated polygons with labels 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
|
||||||
|
- CONF_THRESHOLD : detection threshold
|
||||||
|
- MODEL_WEIGHTS = yolo26n-obb.pt
|
||||||
|
- Input size, normally 1024 for the DOTA-trained model
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 07_obb_detection.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] Rotated boxes are drawn that tilt with the object.
|
||||||
|
- [ ] Labels show class and confidence.
|
||||||
|
- [ ] The default model is trained on DOTA aerial classes, so use aerial images for the best test; 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-obb.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n-obb.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 0` and `sudo 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
|
||||||
|
|
||||||
|
Boxes carry an angle, unlike the axis-aligned boxes in 01_detection.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Oriented bounding boxes task docs](https://docs.ultralytics.com/tasks/obb/)
|
||||||
|
- [DOTA v1 dataset](https://docs.ultralytics.com/datasets/obb/dota-v2/)
|
||||||
|
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [DOTA dataset site](https://captain-whu.github.io/DOTA/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# Task 08: Depth / Distance Estimation Using Python
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Depth / Distance Estimation Using Python
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Implement and test the `08_depth_estimation.py` script on the Jetson Orin Nano. Estimates how far away objects are from the camera and shows the distance next to each detected object on the live feed.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this for obstacle awareness, robotics, safe-distance checks and any case where you need distance, not only position.
|
||||||
|
|
||||||
|
## 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.pt (plus the depth method used in the script)`
|
||||||
|
- 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 08_depth_estimation.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the camera is visible before running:
|
||||||
|
|
||||||
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. Load the YOLO26n detection model (and the depth method used in the script).
|
||||||
|
2. Open the camera feed.
|
||||||
|
3. Detect objects in each frame.
|
||||||
|
4. Estimate the distance for each object (from a depth model or from camera geometry and object size).
|
||||||
|
5. Draw boxes with distance labels, plus 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
|
||||||
|
- CONF_THRESHOLD / IOU_THRESHOLD : detection thresholds
|
||||||
|
- Camera calibration values (focal length, known object size) if geometry is used
|
||||||
|
- MODEL_WEIGHTS and depth model path
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
- Press `Q` to quit the live window
|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
Run `python3 08_depth_estimation.py` and confirm:
|
||||||
|
|
||||||
|
- [ ] Each detected object shows a distance label.
|
||||||
|
- [ ] Distance increases as you move the object away and decreases as it comes closer.
|
||||||
|
- [ ] Compare a few readings with a measuring tape to check accuracy; 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.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `MODEL_WEIGHTS = 'yolo26n.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 0` and `sudo 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
|
||||||
|
|
||||||
|
Adds distance information on top of detection.
|
||||||
|
|
||||||
|
Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Distance calculation guide](https://docs.ultralytics.com/guides/distance-calculation/)
|
||||||
|
- [Depth Anything V2](https://github.com/DepthAnything/Depth-Anything-V2)
|
||||||
|
- [Object detection task docs](https://docs.ultralytics.com/tasks/detect/)
|
||||||
|
- [Pinhole camera model (OpenCV)](https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)
|
||||||
@@ -0,0 +1,416 @@
|
|||||||
|
|
||||||
|
# Marker 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 markers accurately in images and video streams. A dedicated marker dataset is used to train and evaluate the model. The trained model is deployed on an **NVIDIA Jetson Orin Nano** for efficient inference and real-time marker detection using GPU acceleration (TensorRT).
|
||||||
|
|
||||||
|
### 1.1 Objectives
|
||||||
|
|
||||||
|
- Build a custom marker 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 `marker_best.pt`) | Google Colab (GPU) |
|
||||||
|
| 3. Evaluation | Validation set | mAP, precision, recall, curves | Google Colab |
|
||||||
|
| 4. Export | `marker_best.pt` | `marker_best.onnx` | Google Colab / Jetson |
|
||||||
|
| 5. Optimization | ONNX | `marker_best.engine` (TensorRT) | Jetson |
|
||||||
|
| 6. Inference | Live camera / video | Real-time detections | Jetson |
|
||||||
|
|
||||||
|
## 2. Hardware and Software Requirements
|
||||||
|
|
||||||
|
### 2.1 Hardware
|
||||||
|
|
||||||
|
- NVIDIA Jetson Orin Nano (inference device)
|
||||||
|
- Logitech BRIO 100 USB camera
|
||||||
|
- 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/Marker/Marker_detection
|
||||||
|
├── marker_detection.py # detection script
|
||||||
|
├── marker_tracking.py # tracking script (ByteTrack)
|
||||||
|
├── marker_detection_training.ipynb # training notebook (Jupyter)
|
||||||
|
└── models/
|
||||||
|
├── marker_best.pt # trained weights
|
||||||
|
├── marker_best.onnx # ONNX model
|
||||||
|
└── marker_best.engine # TensorRT engine
|
||||||
|
```
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `marker_detection.py` | Real-time marker detection, also used to export the TensorRT engine |
|
||||||
|
| `marker_tracking.py` | Marker tracking with persistent IDs (ByteTrack) |
|
||||||
|
| `marker_detection_training.ipynb` | Notebook used for dataset loading, training, evaluation and ONNX export |
|
||||||
|
| `models/marker_best.pt` | Best trained YOLO26 weights |
|
||||||
|
| `models/marker_best.onnx` | Weights exported to ONNX |
|
||||||
|
| `models/marker_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 the markers using the same type of camera used in deployment (BRIO 100) wherever possible.
|
||||||
|
2. Vary the conditions so the model generalizes:
|
||||||
|
- different distances and angles
|
||||||
|
- different lighting (bright, dim, shadows)
|
||||||
|
- different backgrounds
|
||||||
|
- partial occlusion and motion blur
|
||||||
|
3. If using video, extract frames at a fixed interval:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import cv2, os
|
||||||
|
|
||||||
|
video_path = "marker_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 (for example `marker`) **[ confirm class name(s) ]**.
|
||||||
|
3. Draw a tight bounding box around every marker in each image.
|
||||||
|
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
|
||||||
|
|
||||||
|
Export the dataset in **YOLO (Ultralytics) format**. The folder structure should look like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
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`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
path: /content/dataset
|
||||||
|
train: images/train
|
||||||
|
val: images/val
|
||||||
|
test: images/test
|
||||||
|
|
||||||
|
names:
|
||||||
|
0: marker
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. Step 2 – Model Training (Google Colab)
|
||||||
|
|
||||||
|
The full training workflow is in the notebook `marker_detection_training.ipynb`.
|
||||||
|
|
||||||
|
### 5.1 Set Up the Environment
|
||||||
|
|
||||||
|
1. Open Google Colab and select **Runtime → Change runtime type → GPU**.
|
||||||
|
2. Mount Google Drive (to load the dataset and save the weights):
|
||||||
|
|
||||||
|
```python
|
||||||
|
from google.colab import drive
|
||||||
|
drive.mount('/content/drive')
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install Ultralytics and verify the GPU:
|
||||||
|
|
||||||
|
```python
|
||||||
|
!pip install -U ultralytics
|
||||||
|
!nvidia-smi
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Unzip the dataset:
|
||||||
|
|
||||||
|
```python
|
||||||
|
!unzip -q /content/drive/MyDrive/marker_dataset.zip -d /content/dataset
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 Train the YOLO26 Model
|
||||||
|
|
||||||
|
```python
|
||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
model = YOLO("yolo26n.pt") # pretrained YOLO26 weights [ 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/marker_runs",
|
||||||
|
name="marker_yolo26"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
| Parameter | Value used |
|
||||||
|
|---|---|
|
||||||
|
| Base model | [ yolo26n.pt ] |
|
||||||
|
| Epochs | [ ... ] |
|
||||||
|
| Image size | [ ... ] |
|
||||||
|
| Batch size | [ ... ] |
|
||||||
|
|
||||||
|
📷 *Screenshot: training progress / epoch logs*
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
Copy `best.pt` to the `marker_yolo_weights` folder in Drive and rename it to **`marker_best.pt`**.
|
||||||
|
|
||||||
|
## 6. Step 3 – Evaluation
|
||||||
|
|
||||||
|
### 6.1 Validate the Model
|
||||||
|
|
||||||
|
```python
|
||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
model = YOLO("/content/drive/MyDrive/marker_yolo_weights/marker_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 | 0.9677 |
|
||||||
|
| Recall | 0.9458 |
|
||||||
|
| mAP@50 | 0.9499 |
|
||||||
|
| mAP@50-95 | 0.6995 |
|
||||||
|
|
||||||
|
📷 *Screenshots: `results.png` (loss and metric curves), confusion matrix, PR curve*
|
||||||
|
|
||||||
|
### 6.3 Test on Sample Images
|
||||||
|
|
||||||
|
```python
|
||||||
|
results = model.predict(source="/content/dataset/images/test", conf=0.5, save=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
📷 *Screenshot: sample predictions on test images*
|
||||||
|
|
||||||
|
## 7. Step 4 – Export to ONNX
|
||||||
|
|
||||||
|
ONNX is the intermediate format used before building the TensorRT engine.
|
||||||
|
|
||||||
|
### 7.1 Run the Export in Colab
|
||||||
|
|
||||||
|
```python
|
||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
model = YOLO("/content/drive/MyDrive/marker_yolo_weights/marker_best.pt")
|
||||||
|
model.export(format="onnx", imgsz=416)
|
||||||
|
```
|
||||||
|
|
||||||
|
This generates `marker_best.onnx` next to the `.pt` file.
|
||||||
|
|
||||||
|
📷 *Screenshot: successful export output*
|
||||||
|
|
||||||
|
> **Note:** the export image size (`imgsz`) should match the size used for inference on the Jetson (here, **416**).
|
||||||
|
|
||||||
|
## 8. Step 5 – Jetson Setup
|
||||||
|
|
||||||
|
### 8.1 Prepare the Jetson
|
||||||
|
|
||||||
|
1. Flash JetPack on the Jetson Orin Nano and boot it up.
|
||||||
|
2. Connect the Logitech BRIO 100 to a USB port and confirm it is detected:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install the dependencies (use the PyTorch / Ultralytics versions compatible with your JetPack):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install ultralytics
|
||||||
|
```
|
||||||
|
|
||||||
|
4. (Optional) Maximize performance:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nvpmodel -m 0
|
||||||
|
sudo jetson_clocks
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.2 Copy the Project Files
|
||||||
|
|
||||||
|
Copy the scripts, the notebook and the `models/` folder (with `marker_best.pt`) to the project folder shown in Section 3:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/jetson/projects_2026/Marker/Marker_detection
|
||||||
|
ls
|
||||||
|
ls models
|
||||||
|
```
|
||||||
|
|
||||||
|
## 9. Step 6 – TensorRT Optimization on Jetson
|
||||||
|
|
||||||
|
TensorRT converts the model into an engine optimized for the Jetson GPU, giving much faster inference than the plain `.pt` model.
|
||||||
|
|
||||||
|
### 9.1 Export the TensorRT Engine
|
||||||
|
|
||||||
|
From the project folder run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/jetson/projects_2026/Marker/Marker_detection
|
||||||
|
python3 marker_detection.py --export-tensorrt --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
This produces the following files in `models/`:
|
||||||
|
|
||||||
|
- `marker_best.onnx`
|
||||||
|
- `marker_best.engine`
|
||||||
|
|
||||||
|
The `.engine` file is loaded automatically at inference time.
|
||||||
|
|
||||||
|
📷 *Screenshot: export finished with `.onnx` and `.engine` files listed*
|
||||||
|
|
||||||
|
> **Note:** a TensorRT engine is specific to the device and TensorRT version it was built on. Always build it on the Jetson itself.
|
||||||
|
|
||||||
|
## 10. Step 7 – Real-Time Detection on Jetson
|
||||||
|
|
||||||
|
### 10.1 Run on the Live Camera
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_detection.py --source 0 --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
- `--source 0` selects the first camera (`/dev/video0`). A video file path can be used instead.
|
||||||
|
- `--imgsz 416` must match the size used during export.
|
||||||
|
|
||||||
|
📷 *Screenshot: live detection window with bounding boxes and confidence scores*
|
||||||
|
|
||||||
|
### 10.2 Monitor GPU Usage
|
||||||
|
|
||||||
|
In a second terminal, confirm that the GPU is being used:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo tegrastats
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10.3 Performance
|
||||||
|
|
||||||
|
| Item | Value |
|
||||||
|
|---|---|
|
||||||
|
| Device | Jetson Orin Nano |
|
||||||
|
| Camera | Logitech BRIO 100 |
|
||||||
|
| Input size | 416 × 416 |
|
||||||
|
| Model format | TensorRT (`.engine`) |
|
||||||
|
| FPS | [ ... ] |
|
||||||
|
|
||||||
|
## 11. Step 8 – Marker Tracking
|
||||||
|
|
||||||
|
Tracking assigns a persistent ID to each marker across frames using the Ultralytics `.track()` function with the **ByteTrack** tracker.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_tracking.py --source 0 --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
The same TensorRT engine workflow is used: the engine is built once and loaded automatically at runtime.
|
||||||
|
|
||||||
|
📷 *Screenshot: tracking output with IDs on the markers*
|
||||||
|
|
||||||
|
## 12. 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 | Engine built on a different device / TensorRT version | Rebuild the engine on the Jetson |
|
||||||
|
| Low FPS | Running `.pt` instead of `.engine`, or low power mode | Export the TensorRT engine, run `nvpmodel` and `jetson_clocks` |
|
||||||
|
| Detections missing | Image size mismatch or confidence threshold too high | Use the same `--imgsz` for export and inference, lower `conf` |
|
||||||
|
| Poor accuracy in the field | Dataset lacks real-world variety | Add more images from deployment conditions and retrain |
|
||||||
|
|
||||||
|
## 13. 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 deployment on an NVIDIA Jetson Orin Nano. The trained model reaches a precision of 0.9677, a recall of 0.9458 and an mAP@50 of 0.9499, and runs on live camera streams with GPU acceleration.
|
||||||
|
|
||||||
|
## 14. Quick Command Reference
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Go to the project folder
|
||||||
|
cd /home/jetson/projects_2026/Marker/Marker_detection
|
||||||
|
|
||||||
|
#create the virtual environment
|
||||||
|
python3 -m venv --system-site-packages venv
|
||||||
|
|
||||||
|
#activate the virtual environment
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
# Export TensorRT engine (on Jetson)
|
||||||
|
python3 marker_detection.py --export-tensorrt --imgsz 416
|
||||||
|
|
||||||
|
# Run live detection
|
||||||
|
python3 marker_detection.py --source 0 --imgsz 416
|
||||||
|
|
||||||
|
# Run tracking
|
||||||
|
python3 marker_tracking.py --source 0 --imgsz 416
|
||||||
|
|
||||||
|
# Monitor GPU
|
||||||
|
sudo tegrastats
|
||||||
|
|
||||||
@@ -0,0 +1,466 @@
|
|||||||
|
# Marker Segmentation and Tracking with YOLO26 on NVIDIA Jetson
|
||||||
|
|
||||||
|
End-to-end documentation: polygon 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 segmentation** model to detect markers and outline their exact shape (pixel-level masks) in images and video streams. A dedicated marker dataset annotated with **polygons** is used to train and evaluate the model. The trained model is deployed on an **NVIDIA Jetson Orin Nano**, converted to a **TensorRT** engine, and used for real-time marker segmentation and tracking on the GPU.
|
||||||
|
|
||||||
|
Compared with the detection project, segmentation gives the exact marker outline instead of only a bounding box.
|
||||||
|
|
||||||
|
### 1.1 Objectives
|
||||||
|
|
||||||
|
- Build a marker dataset with polygon annotations.
|
||||||
|
- Train and evaluate a YOLO26 segmentation model.
|
||||||
|
- Export the model to ONNX and then to a TensorRT engine (FP16).
|
||||||
|
- Run real-time segmentation and tracking (persistent IDs) on a Jetson with a live camera.
|
||||||
|
|
||||||
|
### 1.2 Pipeline at a Glance
|
||||||
|
|
||||||
|
| Stage | Input | Output | Where it runs |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 1. Dataset creation | Raw images / video frames | Polygon-annotated dataset (YOLO segmentation format) | PC |
|
||||||
|
| 2. Training | Dataset + pretrained YOLO26 segmentation weights | `best.pt` (renamed `marker_seg_best.pt`) | Google Colab (GPU) |
|
||||||
|
| 3. Evaluation | Validation set | Box and mask mAP, precision, recall, curves | Google Colab |
|
||||||
|
| 4. Export | `marker_seg_best.pt` | `marker_seg_best.onnx` | Google Colab / Jetson |
|
||||||
|
| 5. Optimization | ONNX | `marker_seg_best.engine` (TensorRT, FP16) | Jetson |
|
||||||
|
| 6. Inference | Live camera / video | Real-time masks with tracking IDs | Jetson |
|
||||||
|
|
||||||
|
## 2. Hardware and Software Requirements
|
||||||
|
|
||||||
|
### 2.1 Hardware
|
||||||
|
|
||||||
|
- NVIDIA Jetson Orin Nano (inference device)
|
||||||
|
- Logitech BRIO 100 USB camera (a CSI camera is also supported)
|
||||||
|
- Development PC / laptop with internet access
|
||||||
|
|
||||||
|
### 2.2 Software
|
||||||
|
|
||||||
|
| Component | Details |
|
||||||
|
|---|---|
|
||||||
|
| Model | YOLO26 segmentation (Ultralytics) |
|
||||||
|
| Tracker | ByteTrack (default), BoT-SORT optional |
|
||||||
|
| Training platform | Google Colab with GPU runtime |
|
||||||
|
| Annotation tool | **[ e.g., Roboflow / CVAT / Labelme ]** |
|
||||||
|
| Export formats | ONNX, TensorRT (`.engine`, FP16) |
|
||||||
|
| Jetson OS | JetPack **[ version ]** |
|
||||||
|
| Languages / libraries | Python 3, Ultralytics, OpenCV, PyTorch |
|
||||||
|
|
||||||
|
## 3. Project Structure
|
||||||
|
|
||||||
|
The project lives on the Jetson at **[ replace with your path, e.g., /home/jetson/projects_2026/Marker/Marker_segmentation ]**:
|
||||||
|
|
||||||
|
```
|
||||||
|
Marker_segmentation
|
||||||
|
├── marker_segmentation.py # segmentation + tracking script
|
||||||
|
├── marker_segmentation_training.ipynb # training notebook (Jupyter)
|
||||||
|
└── models/
|
||||||
|
├── marker_seg_best.pt # trained weights
|
||||||
|
├── marker_seg_best.onnx # ONNX model
|
||||||
|
└── marker_seg_best.engine # TensorRT engine
|
||||||
|
```
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `marker_segmentation.py` | Real-time marker segmentation and tracking; also used to export ONNX and the TensorRT engine |
|
||||||
|
| `marker_segmentation_training.ipynb` | Notebook used for dataset loading, training, evaluation and ONNX export |
|
||||||
|
| `models/marker_seg_best.pt` | Best trained YOLO26 segmentation weights (class 0 = marker) |
|
||||||
|
| `models/marker_seg_best.onnx` | Weights exported to ONNX |
|
||||||
|
| `models/marker_seg_best.engine` | TensorRT engine built on the Jetson; loaded automatically when it sits next to the `.pt` file |
|
||||||
|
|
||||||
|
## 4. Step 1 – Dataset Creation (Polygon Annotation)
|
||||||
|
|
||||||
|
### 4.1 Collect Images
|
||||||
|
|
||||||
|
1. Capture images and video of the markers using the same type of camera used in deployment (BRIO 100) wherever possible.
|
||||||
|
2. Vary the conditions so the model generalizes:
|
||||||
|
- different distances and angles
|
||||||
|
- different lighting (bright, dim, shadows)
|
||||||
|
- different backgrounds
|
||||||
|
- partial occlusion and motion blur
|
||||||
|
3. If using video, extract frames at a fixed interval:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import cv2, os
|
||||||
|
|
||||||
|
video_path = "marker_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 with Polygons
|
||||||
|
|
||||||
|
1. Upload the images to the annotation tool.
|
||||||
|
2. Create the class (for example `marker`) **[ confirm class name ]**.
|
||||||
|
3. For every marker, click points around its outline to draw a **polygon** that follows the marker edge closely.
|
||||||
|
4. Review the polygons and fix any inaccurate outlines.
|
||||||
|
|
||||||
|
📷 *Screenshot: annotation tool with polygon masks*
|
||||||
|
|
||||||
|
### 4.3 Split the Dataset
|
||||||
|
|
||||||
|
Split into training, validation and test sets **[ confirm the ratio, e.g., 70 / 20 / 10 ]**:
|
||||||
|
|
||||||
|
| Split | Images |
|
||||||
|
|---|---|
|
||||||
|
| Train | [ ... ] |
|
||||||
|
| Validation | [ ... ] |
|
||||||
|
| Test | [ ... ] |
|
||||||
|
|
||||||
|
### 4.4 Export in YOLO Segmentation Format
|
||||||
|
|
||||||
|
Export the dataset in **YOLO segmentation (Ultralytics) format**. The folder structure is the same as for detection:
|
||||||
|
|
||||||
|
```
|
||||||
|
dataset/
|
||||||
|
├── images/
|
||||||
|
│ ├── train/
|
||||||
|
│ ├── val/
|
||||||
|
│ └── test/
|
||||||
|
├── labels/
|
||||||
|
│ ├── train/
|
||||||
|
│ ├── val/
|
||||||
|
│ └── test/
|
||||||
|
└── data.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Each label file contains one line per object, with the polygon points instead of a box:
|
||||||
|
|
||||||
|
```
|
||||||
|
<class_id> <x1> <y1> <x2> <y2> ... <xn> <yn> (all coordinates normalized 0–1)
|
||||||
|
```
|
||||||
|
|
||||||
|
Example `data.yaml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
path: /content/dataset
|
||||||
|
train: images/train
|
||||||
|
val: images/val
|
||||||
|
test: images/test
|
||||||
|
|
||||||
|
names:
|
||||||
|
0: marker
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. Step 2 – Model Training (Google Colab)
|
||||||
|
|
||||||
|
The full training workflow is in the notebook `marker_segmentation_training.ipynb`.
|
||||||
|
|
||||||
|
### 5.1 Set Up the Environment
|
||||||
|
|
||||||
|
1. Open Google Colab and select **Runtime → Change runtime type → GPU**.
|
||||||
|
2. Mount Google Drive (to load the dataset and save the weights):
|
||||||
|
|
||||||
|
```python
|
||||||
|
from google.colab import drive
|
||||||
|
drive.mount('/content/drive')
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install Ultralytics and verify the GPU:
|
||||||
|
|
||||||
|
```python
|
||||||
|
!pip install -U ultralytics
|
||||||
|
!nvidia-smi
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Unzip the dataset:
|
||||||
|
|
||||||
|
```python
|
||||||
|
!unzip -q /content/drive/MyDrive/marker_seg_dataset.zip -d /content/dataset
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 Train the YOLO26 Segmentation Model
|
||||||
|
|
||||||
|
Use a segmentation checkpoint (the `-seg` weights):
|
||||||
|
|
||||||
|
```python
|
||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
model = YOLO("yolo26n-seg.pt") # pretrained YOLO26 segmentation weights [ 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/marker_seg_runs",
|
||||||
|
name="marker_seg_yolo26"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
| Parameter | Value used |
|
||||||
|
|---|---|
|
||||||
|
| Base model | [ yolo26n-seg.pt ] |
|
||||||
|
| Epochs | [ ... ] |
|
||||||
|
| Image size | [ ... ] |
|
||||||
|
| Batch size | [ ... ] |
|
||||||
|
|
||||||
|
📷 *Screenshot: training progress / epoch logs*
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
Copy `best.pt` to a Drive folder and rename it to **`marker_seg_best.pt`**.
|
||||||
|
|
||||||
|
## 6. Step 3 – Evaluation
|
||||||
|
|
||||||
|
### 6.1 Validate the Model
|
||||||
|
|
||||||
|
A segmentation model is evaluated on both the **box** and the **mask** outputs:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
model = YOLO("/content/drive/MyDrive/marker_seg_weights/marker_seg_best.pt")
|
||||||
|
metrics = model.val(data="/content/dataset/data.yaml")
|
||||||
|
|
||||||
|
print("Box mAP50 :", metrics.box.map50)
|
||||||
|
print("Box mAP50-95 :", metrics.box.map)
|
||||||
|
print("Mask mAP50 :", metrics.seg.map50)
|
||||||
|
print("Mask mAP50-95 :", metrics.seg.map)
|
||||||
|
print("Mask Precision:", metrics.seg.mp)
|
||||||
|
print("Mask Recall :", metrics.seg.mr)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.2 Results
|
||||||
|
|
||||||
|
| Metric | Box | Mask |
|
||||||
|
|---|---|---|
|
||||||
|
| Precision | [ ... ] | [ ... ] |
|
||||||
|
| Recall | [ ... ] | [ ... ] |
|
||||||
|
| mAP@50 | [ ... ] | [ ... ] |
|
||||||
|
| mAP@50-95 | [ ... ] | [ ... ] |
|
||||||
|
|
||||||
|
📷 *Screenshots: `results.png` (loss and metric curves), confusion matrix, PR curve*
|
||||||
|
|
||||||
|
### 6.3 Test on Sample Images
|
||||||
|
|
||||||
|
```python
|
||||||
|
results = model.predict(source="/content/dataset/images/test", conf=0.5, save=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
📷 *Screenshot: sample predictions with segmentation masks on test images*
|
||||||
|
|
||||||
|
## 7. Step 4 – Export to ONNX
|
||||||
|
|
||||||
|
ONNX is the intermediate format used before building the TensorRT engine.
|
||||||
|
|
||||||
|
### 7.1 Run the Export in Colab
|
||||||
|
|
||||||
|
```python
|
||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
model = YOLO("/content/drive/MyDrive/marker_seg_weights/marker_seg_best.pt")
|
||||||
|
model.export(format="onnx", imgsz=416)
|
||||||
|
```
|
||||||
|
|
||||||
|
This generates `marker_seg_best.onnx` next to the `.pt` file.
|
||||||
|
|
||||||
|
📷 *Screenshot: successful export output*
|
||||||
|
|
||||||
|
> **Note:** a TensorRT engine has a **fixed input size**. Use the same `--imgsz` for export and for inference (here, **416**).
|
||||||
|
|
||||||
|
## 8. Step 5 – Jetson Setup
|
||||||
|
|
||||||
|
### 8.1 Prepare the Jetson
|
||||||
|
|
||||||
|
1. Flash JetPack on the Jetson Orin Nano and boot it up.
|
||||||
|
2. Connect the Logitech BRIO 100 to a USB port and confirm it is detected:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install the dependencies (use the PyTorch / Ultralytics versions compatible with your JetPack):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install ultralytics
|
||||||
|
```
|
||||||
|
|
||||||
|
4. (Optional) Maximize performance:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nvpmodel -m 0
|
||||||
|
sudo jetson_clocks
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.2 Copy the Project Files
|
||||||
|
|
||||||
|
Copy the script, the notebook and the `models/` folder (with `marker_seg_best.pt`) to the project folder shown in Section 3:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd <your project folder>
|
||||||
|
ls
|
||||||
|
ls models
|
||||||
|
```
|
||||||
|
|
||||||
|
## 9. Step 6 – TensorRT Optimization on Jetson
|
||||||
|
|
||||||
|
TensorRT converts the model into an engine optimized for the Jetson GPU, giving much faster inference than the plain `.pt` model.
|
||||||
|
|
||||||
|
### 9.1 Export the TensorRT Engine
|
||||||
|
|
||||||
|
The script converts `.pt` → `.onnx` → `.engine` (FP16) in one step. Run it once from the project folder:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --export-tensorrt --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
To export only the ONNX file, without the engine:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --export-onnx --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
This produces the following files in `models/`:
|
||||||
|
|
||||||
|
- `marker_seg_best.onnx`
|
||||||
|
- `marker_seg_best.engine`
|
||||||
|
|
||||||
|
If `marker_seg_best.engine` exists next to `marker_seg_best.pt`, it is loaded automatically at inference. Otherwise the `.pt` file is used.
|
||||||
|
|
||||||
|
📷 *Screenshot: export finished with `.onnx` and `.engine` files listed*
|
||||||
|
|
||||||
|
> **Note:** a TensorRT engine is specific to the device and TensorRT version it was built on. Always build it on the Jetson itself.
|
||||||
|
|
||||||
|
## 10. Step 7 – Real-Time Segmentation and Tracking on Jetson
|
||||||
|
|
||||||
|
The script runs segmentation and tracking together. Each marker is outlined with a mask and keeps a persistent ID across frames (ByteTrack by default).
|
||||||
|
|
||||||
|
### 10.1 Run on the Live Camera
|
||||||
|
|
||||||
|
USB camera:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
CSI camera:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --source csi --imgsz 416
|
||||||
|
```
|
||||||
|
|
||||||
|
Video file, with the result saved:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --source my_video.mp4 --imgsz 416 --save out.mp4
|
||||||
|
```
|
||||||
|
|
||||||
|
- `--source 0` selects the first USB camera (`/dev/video0`).
|
||||||
|
- `--imgsz 416` must match the size used during export.
|
||||||
|
|
||||||
|
📷 *Screenshot: live segmentation window with masks, tracking IDs and confidence scores*
|
||||||
|
|
||||||
|
### 10.2 Optional Settings
|
||||||
|
|
||||||
|
Use BoT-SORT instead of ByteTrack:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416 --tracker botsort.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Run headless (for example over SSH, with no display window):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416 --no-display
|
||||||
|
```
|
||||||
|
|
||||||
|
Debug mode, which prints what the model returned for each frame:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416 --debug
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10.3 Monitor GPU Usage
|
||||||
|
|
||||||
|
In a second terminal, confirm that the GPU is being used:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo tegrastats
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10.4 Performance
|
||||||
|
|
||||||
|
| Item | Value |
|
||||||
|
|---|---|
|
||||||
|
| Device | Jetson Orin Nano |
|
||||||
|
| Camera | Logitech BRIO 100 |
|
||||||
|
| Input size | 416 × 416 |
|
||||||
|
| Model format | TensorRT (`.engine`, FP16) |
|
||||||
|
| FPS | [ ... ] |
|
||||||
|
|
||||||
|
## 11. Command-Line Options
|
||||||
|
|
||||||
|
| Option | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `--export-tensorrt` | Export `.pt` → `.onnx` → `.engine` (FP16) |
|
||||||
|
| `--export-onnx` | Export the ONNX file only |
|
||||||
|
| `--source` | `0` for a USB camera, `csi` for a CSI camera, or a video file path |
|
||||||
|
| `--imgsz` | Input size; must be the same for export and inference |
|
||||||
|
| `--save` | Save the output video to the given file |
|
||||||
|
| `--tracker` | Tracker configuration (`bytetrack.yaml` by default, or `botsort.yaml`) |
|
||||||
|
| `--no-display` | Run without a display window |
|
||||||
|
| `--debug` | Print the model output for each frame |
|
||||||
|
|
||||||
|
## 12. 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 | Engine built on a different device / TensorRT version | Rebuild the engine on the Jetson |
|
||||||
|
| Wrong results with the engine | `--imgsz` differs from the export size | Use the same `--imgsz` for export and inference |
|
||||||
|
| Low FPS | Running `.pt` instead of `.engine`, or low power mode | Export the TensorRT engine, run `nvpmodel` and `jetson_clocks` |
|
||||||
|
| No window on SSH | No display available | Use `--no-display` (and `--save` to keep the output) |
|
||||||
|
| No masks or IDs appear | Model returned nothing for the frame | Run with `--debug` and check the output |
|
||||||
|
| Poor mask quality | Polygons in the dataset are too rough or too few images | Improve the annotations, add more images and retrain |
|
||||||
|
|
||||||
|
## 13. Conclusion
|
||||||
|
|
||||||
|
The project covers the complete workflow of a custom segmentation system: polygon dataset creation, YOLO26 segmentation training and evaluation on Google Colab, export to ONNX, TensorRT optimization, and real-time segmentation and tracking on an NVIDIA Jetson Orin Nano. The result is an efficient marker segmentation system that gives the exact outline of each marker and runs on live camera streams with GPU acceleration.
|
||||||
|
|
||||||
|
## 14. Quick Command Reference
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Export TensorRT engine (run once, on the Jetson)
|
||||||
|
python3 marker_segmentation.py --export-tensorrt --imgsz 416
|
||||||
|
|
||||||
|
# Live tracking, USB camera
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416
|
||||||
|
|
||||||
|
# Live tracking, CSI camera
|
||||||
|
python3 marker_segmentation.py --source csi --imgsz 416
|
||||||
|
|
||||||
|
# Video file, save the result
|
||||||
|
python3 marker_segmentation.py --source my_video.mp4 --imgsz 416 --save out.mp4
|
||||||
|
|
||||||
|
# BoT-SORT tracker
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416 --tracker botsort.yaml
|
||||||
|
|
||||||
|
# Headless over SSH
|
||||||
|
python3 marker_segmentation.py --source 0 --imgsz 416 --no-display
|
||||||
|
|
||||||
|
# Monitor GPU
|
||||||
|
sudo tegrastats
|
||||||
|
```
|
||||||
@@ -0,0 +1,393 @@
|
|||||||
|
# Weld Defect Detection on Jetson Orin Nano (YOLO11 + TensorRT)
|
||||||
|
|
||||||
|
Real-time detection of three weld classes on a Jetson Orin Nano, using a YOLO11s model trained in Google Colab and deployed as a TensorRT engine.
|
||||||
|
|
||||||
|
Classes (training order) and the box colour used when drawing:
|
||||||
|
|
||||||
|
| ID | Class | Box colour |
|
||||||
|
|---|---|---|
|
||||||
|
| 0 | Bad Weld | Red |
|
||||||
|
| 1 | Good Weld | Green |
|
||||||
|
| 2 | Defect | Orange |
|
||||||
|
|
||||||
|
The script reads the class names from the model itself and matches colours by name, so the order above does not affect it.
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
1. [What This Project Does](#1-what-this-project-does)
|
||||||
|
2. [Folder Structure](#2-folder-structure)
|
||||||
|
3. [What Each File Is For](#3-what-each-file-is-for)
|
||||||
|
4. [One-Time Setup on the Jetson](#4-one-time-setup-on-the-jetson)
|
||||||
|
5. [Training Summary](#5-training-summary)
|
||||||
|
6. [How to Run the Project, Start to Finish](#6-how-to-run-the-project-start-to-finish)
|
||||||
|
7. [How It Works](#7-how-it-works)
|
||||||
|
8. [Changing Things](#8-changing-things)
|
||||||
|
9. [Troubleshooting](#9-troubleshooting)
|
||||||
|
10. [Quick Command Cheat Sheet](#10-quick-command-cheat-sheet)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. What This Project Does
|
||||||
|
|
||||||
|
Training happens **once** in Google Colab:
|
||||||
|
|
||||||
|
```
|
||||||
|
two datasets -> merge -> train YOLO11s -> best.pt
|
||||||
|
```
|
||||||
|
|
||||||
|
Deployment happens on the Jetson, using only two scripts:
|
||||||
|
|
||||||
|
| Script | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `convert.py` | `best_weld.pt` -> `best_weld.onnx` -> `best_weld.engine` |
|
||||||
|
| `infer.py` | Detection on images, video files, or a live camera |
|
||||||
|
|
||||||
|
**Why an engine?** A TensorRT `.engine` file runs much faster on the Jetson GPU than the raw `.pt` file. This matters for live video.
|
||||||
|
|
||||||
|
Each script is fully self-contained. There is no shared helper file any more, so you can copy either script on its own.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Folder Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
/home/jetson/projects_2026/welding/
|
||||||
|
├── convert.py # converts .pt -> .onnx -> .engine
|
||||||
|
├── infer.py # detection on images, video, or live camera
|
||||||
|
├── README.txt # project documentation
|
||||||
|
├── models/
|
||||||
|
│ ├── best_weld.pt # trained weights from Colab
|
||||||
|
│ ├── best_weld.onnx # created by convert.py
|
||||||
|
│ └── best_weld.engine # created by convert.py (used for inference)
|
||||||
|
├── test_images/ # your input images
|
||||||
|
├── test_video.mp4 # your input video
|
||||||
|
├── results/ # ALL outputs are saved here (created automatically)
|
||||||
|
├── venv/ # Python virtual environment (made in section 4)
|
||||||
|
└── __pycache__/ # made automatically by Python, safe to delete
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. What Each File Is For
|
||||||
|
|
||||||
|
### 3.1 `convert.py` (run once, on the Jetson)
|
||||||
|
|
||||||
|
Converts `models/best_weld.pt` into `models/best_weld.onnx` and then into `models/best_weld.engine`. It skips any output that already exists unless you add `--force`.
|
||||||
|
|
||||||
|
| Option | Description |
|
||||||
|
|---|---|
|
||||||
|
| `--weights` | Input `.pt` file. Default: `models/best_weld.pt` |
|
||||||
|
| `--imgsz` | Input size baked into the engine. Default: `640`. It must match the size used at inference. |
|
||||||
|
| `--precision` | `fp16` (default), `fp32` or `int8`. INT8 also needs `--data`. |
|
||||||
|
| `--method` | `ultralytics` (default): Ultralytics builds the engine. `trtexec`: NVIDIA's trtexec tool builds it from the ONNX file, then class-name metadata is added. |
|
||||||
|
| `--data` | Dataset yaml file, only for INT8 calibration. |
|
||||||
|
| `--workspace` | TensorRT workspace in GB. Default: `4`. |
|
||||||
|
| `--force` | Rebuild even if the outputs already exist. |
|
||||||
|
|
||||||
|
### 3.2 `infer.py` (images, video files and live camera in one script)
|
||||||
|
|
||||||
|
Loads the engine, runs detection, draws coloured boxes and labels, prints the class counts, and saves the result to `results/`.
|
||||||
|
|
||||||
|
The mode is chosen automatically from `--source`:
|
||||||
|
|
||||||
|
| `--source` value | Mode |
|
||||||
|
|---|---|
|
||||||
|
| An image file or a folder of images | Image mode |
|
||||||
|
| A video file, `0`, `1` or `csi` | Video / live camera mode |
|
||||||
|
| No `--source` at all | First image found; if there is no image, first video found |
|
||||||
|
|
||||||
|
- **Image mode** saves `results/<name>_out.<ext>` for every image.
|
||||||
|
- **Video mode** draws FPS and class counts on every frame and saves `results/<name>_out.mp4` (camera output is `results/camera_out.mp4`).
|
||||||
|
|
||||||
|
| Option | Description |
|
||||||
|
|---|---|
|
||||||
|
| `--source` | Image file, image folder, video file, `0` (USB camera) or `csi` (Jetson camera). |
|
||||||
|
| `--weights` | Use a different engine file. |
|
||||||
|
| `--save-dir` | Output folder. Default: `results/` |
|
||||||
|
| `--save` | (video) exact output video path. |
|
||||||
|
| `--no-save` | (video) do not write an output video. |
|
||||||
|
| `--show` | (images) open a preview window; press `q` to stop. |
|
||||||
|
| `--no-display` | (video) do not open a window. Use this over SSH. |
|
||||||
|
| `--imgsz` | Must match the engine. Default: `640`. |
|
||||||
|
| `--conf` | Minimum confidence to show a box. Default: `0.25`. |
|
||||||
|
| `--iou` | Overlap threshold for merging boxes. Default: `0.45`. |
|
||||||
|
| `--device` | Default `"0"` (the Jetson GPU). |
|
||||||
|
| `--debug` | Print every candidate box, even below `--conf`. |
|
||||||
|
|
||||||
|
In a preview window press `q` to quit. In the terminal `Ctrl+C` also stops a video or camera run cleanly, and the output file is still saved.
|
||||||
|
|
||||||
|
Settings (paths, `IMGSZ`, `CONF`, `IOU`, colours) are at the top of each script in the `CONFIG` block.
|
||||||
|
|
||||||
|
### 3.3 Folders and Other Files
|
||||||
|
|
||||||
|
| Item | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `models/` | Holds the three model files. Only `best_weld.engine` is used at inference time. Keep the `.pt` so you can rebuild the engine later. |
|
||||||
|
| `test_images/` | Your input images. |
|
||||||
|
| `test_video.mp4` | Your input video. |
|
||||||
|
| `results/` | Created automatically if it is missing. |
|
||||||
|
| `venv/` | The isolated Python environment for this project. |
|
||||||
|
| `__pycache__/` | Python's compiled cache. Regenerated automatically and can be deleted. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. One-Time Setup on the Jetson
|
||||||
|
|
||||||
|
### 4.1 Prerequisites
|
||||||
|
|
||||||
|
Your Jetson should already have JetPack (CUDA, TensorRT, cuDNN) and NVIDIA's Jetson build of PyTorch. Check with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 --version
|
||||||
|
python3 -c "import torch; print(torch.__version__, torch.cuda.is_available())"
|
||||||
|
python3 -c "import tensorrt; print(tensorrt.__version__)"
|
||||||
|
```
|
||||||
|
|
||||||
|
`torch.cuda.is_available()` must print `True`. If it prints `False` you have a CPU-only torch, and you need NVIDIA's Jetson wheel for your JetPack version before continuing.
|
||||||
|
|
||||||
|
### 4.2 Create the Virtual Environment
|
||||||
|
|
||||||
|
> **Important:** the flag `--system-site-packages` is needed on Jetson. It lets the venv see the JetPack packages (TensorRT, and the Jetson torch if it was installed system-wide), which cannot be installed with plain pip.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y python3-venv python3-pip
|
||||||
|
|
||||||
|
cd /home/jetson/projects_2026/welding
|
||||||
|
python3 -m venv --system-site-packages venv
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
pip install --upgrade pip
|
||||||
|
pip install ultralytics
|
||||||
|
```
|
||||||
|
|
||||||
|
Then verify inside the venv:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -c "import torch; print('torch', torch.__version__, 'cuda', torch.cuda.is_available())"
|
||||||
|
python -c "import tensorrt; print('tensorrt', tensorrt.__version__)"
|
||||||
|
python -c "import ultralytics, cv2; print('ultralytics', ultralytics.__version__, 'cv2', cv2.__version__)"
|
||||||
|
```
|
||||||
|
|
||||||
|
If any of these print `False` or fail to import, see [section 9](#9-troubleshooting).
|
||||||
|
|
||||||
|
### 4.3 Optional Extras
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install onnx onnxslim onnxruntime
|
||||||
|
```
|
||||||
|
|
||||||
|
You only need these if the ONNX export step complains about a missing package.
|
||||||
|
|
||||||
|
### 4.4 Using the Environment Later
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/jetson/projects_2026/welding
|
||||||
|
source venv/bin/activate # start
|
||||||
|
deactivate # stop
|
||||||
|
```
|
||||||
|
|
||||||
|
Activate the venv in every new terminal before running the scripts.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Training Summary
|
||||||
|
|
||||||
|
*(from `welding_combined_yolo_colab.ipynb`)*
|
||||||
|
|
||||||
|
Training was done in Google Colab on a T4 GPU. It is not repeated on the Jetson.
|
||||||
|
|
||||||
|
### 5.1 Datasets
|
||||||
|
|
||||||
|
Two public welding datasets are downloaded from Google Drive: **"The Welding Defect Dataset v2"** (`archive.zip`) and **"welding v1i yolov11"**.
|
||||||
|
|
||||||
|
### 5.2 Merge into One 3-Class Dataset
|
||||||
|
|
||||||
|
The notebook writes `merge_core.py`, which does the following:
|
||||||
|
|
||||||
|
- Checks that the second dataset's unnamed classes 0/1/2 match Bad Weld / Good Weld / Defect by comparing boxes on images that both datasets contain.
|
||||||
|
- Removes near-identical images using perceptual hashing.
|
||||||
|
- Re-splits by groups of similar images so look-alike images never sit in both train and test (this avoids leakage).
|
||||||
|
- Keeps validation and test free of augmented copies.
|
||||||
|
|
||||||
|
### 5.3 Resulting Dataset
|
||||||
|
|
||||||
|
| Item | Value |
|
||||||
|
|---|---|
|
||||||
|
| Images in | about 4,179 |
|
||||||
|
| Images out | 2,559 |
|
||||||
|
| Train | 2,044 |
|
||||||
|
| Validation | 310 |
|
||||||
|
| Test | 205 |
|
||||||
|
| Boxes | about 8,700 |
|
||||||
|
| Cross-split near-duplicates | 0 |
|
||||||
|
|
||||||
|
### 5.4 Training Settings
|
||||||
|
|
||||||
|
Training starts from `yolo11s.pt`:
|
||||||
|
|
||||||
|
| Setting | Value |
|
||||||
|
|---|---|
|
||||||
|
| Epochs / patience | 200 / 40 |
|
||||||
|
| Image size / batch | 640 / 16 |
|
||||||
|
| Optimizer | AdamW |
|
||||||
|
| Initial learning rate (`lr0`) | 0.002, cosine learning rate |
|
||||||
|
| Mosaic | 1.0 (switched off for the last 20 epochs) |
|
||||||
|
| `fliplr` | 0.5 |
|
||||||
|
| `hsv_h` / `hsv_s` / `hsv_v` | 0.015 / 0.5 / 0.4 |
|
||||||
|
|
||||||
|
### 5.5 Output and Evaluation
|
||||||
|
|
||||||
|
- **Output:** `weld_runs/yolo11s_combined/weights/best.pt` on Google Drive.
|
||||||
|
- **Evaluation:** the notebook runs validation on the test split and prints mAP50-95, mAP50 and the per-class AP.
|
||||||
|
|
||||||
|
Because training used `imgsz 640`, the Jetson engine is also built at 640.
|
||||||
|
|
||||||
|
### 5.6 Copying the Weights to the Jetson
|
||||||
|
|
||||||
|
Download `best.pt` from Drive, then run this on your computer:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scp best.pt jetson@<JETSON_IP>:/home/jetson/projects_2026/welding/models/best_weld.pt
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. How to Run the Project, Start to Finish
|
||||||
|
|
||||||
|
Open a terminal and go to the project:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/jetson/projects_2026/welding
|
||||||
|
source venv/bin/activate
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 1: Build the Engine (once, takes several minutes)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 convert.py
|
||||||
|
```
|
||||||
|
|
||||||
|
If `models/best_weld.onnx` and `models/best_weld.engine` already exist, they are skipped. Add `--force` to rebuild.
|
||||||
|
|
||||||
|
### Step 2: Detect on Images
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 infer.py --source test_images
|
||||||
|
python3 infer.py --source test_images/weld1.jpg --show
|
||||||
|
```
|
||||||
|
|
||||||
|
The first command does every image in the folder. Outputs go to `results/<name>_out.jpg`.
|
||||||
|
|
||||||
|
### Step 3: Detect on a Video File
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 infer.py --source test_video.mp4
|
||||||
|
python3 infer.py --source test_video.mp4 --no-display
|
||||||
|
```
|
||||||
|
|
||||||
|
Output goes to `results/test_video_out.mp4`.
|
||||||
|
|
||||||
|
### Step 4: Detect on a Live Camera
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 infer.py --source 0
|
||||||
|
python3 infer.py --source csi
|
||||||
|
python3 infer.py --source 0 --no-display
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `0` for a USB camera and `csi` for the Jetson camera. Add `--no-display` when working over SSH. Output goes to `results/camera_out.mp4`.
|
||||||
|
|
||||||
|
Running `python3 infer.py` with no `--source` uses the first image found (or the first video if there is no image).
|
||||||
|
|
||||||
|
### Check the Outputs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ls -lh results/
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. How It Works
|
||||||
|
|
||||||
|
1. **Conversion.** `convert.py` exports the PyTorch weights to ONNX, a portable format. TensorRT then compiles the ONNX graph into an engine optimised for this exact GPU. FP16 precision roughly doubles speed on the Orin Nano with very little loss of accuracy.
|
||||||
|
2. **Loading.** The engine file carries a small metadata header with the class names and image size, which Ultralytics reads.
|
||||||
|
3. **Warm-up.** The first inference initialises CUDA and TensorRT and is slow, so one dummy frame is run before real work starts. The FPS counter is therefore not distorted.
|
||||||
|
4. **Detection.** Each frame is resized to 640x640, the engine produces candidate boxes, boxes below `CONF` are dropped, and overlapping boxes are merged with NMS (`IOU`).
|
||||||
|
5. **Drawing and saving.** Boxes are drawn in each class colour, the class counts are printed, and the results are written to `results/`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Changing Things
|
||||||
|
|
||||||
|
### Move the project
|
||||||
|
|
||||||
|
Change `BASE_DIR` in `convert.py` and `infer.py`, or run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export WELD_HOME=/new/path
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use a different input size
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 convert.py --imgsz 416 --force
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `IMGSZ = 416` in `infer.py` (and in `convert.py`). 416 is faster but less accurate; 640 is slower but more accurate.
|
||||||
|
|
||||||
|
### Catch more small defects
|
||||||
|
|
||||||
|
Use `--conf 0.15` (more false alarms are possible).
|
||||||
|
|
||||||
|
### Fewer false alarms
|
||||||
|
|
||||||
|
Use `--conf 0.40`.
|
||||||
|
|
||||||
|
### Use a new model
|
||||||
|
|
||||||
|
Copy it to `models/best_weld.pt`, then run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 convert.py --force
|
||||||
|
```
|
||||||
|
|
||||||
|
### Change box colours
|
||||||
|
|
||||||
|
Edit `CLASS_COLORS` in `infer.py`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. Troubleshooting
|
||||||
|
|
||||||
|
| Problem | Cause and fix |
|
||||||
|
|---|---|
|
||||||
|
| **Weights not found ... `best_weld.engine`** | The engine is not built yet. Run `python3 convert.py`. |
|
||||||
|
| **Weights not found ... `best_weld.pt`** | Copy the `.pt` file to `models/best_weld.pt`, or pass `--weights path`. |
|
||||||
|
| **`torch.cuda.is_available()` is `False`** | The venv is using a CPU-only torch. Recreate the venv with `--system-site-packages`. If pip installed its own torch, run `pip uninstall torch torchvision` so the Jetson wheel is used. |
|
||||||
|
| **No module named `tensorrt`** | The venv was created without `--system-site-packages`. Recreate it as shown in section 4.2. |
|
||||||
|
| **Engine fails to load or gives errors** | The engine was built on another machine or a different JetPack or TensorRT version. Rebuild it on this Jetson with `--force`. |
|
||||||
|
| **Wrong or garbage detections** | `imgsz` mismatch. The engine and `IMGSZ` must be the same (640). |
|
||||||
|
| **Class names show as 0, 1, 2** | The engine has no metadata. Rebuild with the default `--method ultralytics`. |
|
||||||
|
| **"cannot connect to X server" or a window error** | You are running over SSH. Add `--no-display` (video) and do not use `--show` (images). |
|
||||||
|
| **Could not open source: 0** | The USB camera is not at index 0. Try `--source 1`, or check `ls /dev/video*`. |
|
||||||
|
| **CSI camera fails** | Check `nvarguscamerasrc`. If you installed `opencv-python` with pip, it may hide the JetPack OpenCV that has GStreamer support. Run `pip uninstall opencv-python` and use the system OpenCV. |
|
||||||
|
| **`trtexec` not found** | Run `export PATH=$PATH:/usr/src/tensorrt/bin`, or use the default `--method ultralytics`. |
|
||||||
|
| **Low FPS** | Check the power mode with `sudo nvpmodel -q`, run `sudo jetson_clocks`, use FP16, and try a 416 engine (`--imgsz 416 --force` in `convert.py`, and `IMGSZ = 416` in `infer.py`). |
|
||||||
|
| **Nothing detected** | Run with `--debug --conf 0.15` to see low-confidence boxes in the terminal. |
|
||||||
|
| **Output video will not play** | Try VLC, or change the codec `"mp4v"` in `infer.py`. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. Quick Command Cheat Sheet
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/jetson/projects_2026/welding && source venv/bin/activate
|
||||||
|
|
||||||
|
python3 convert.py # build the engine
|
||||||
|
python3 infer.py --source ./test_images # test image folder
|
||||||
|
python3 infer.py --source test_video.mp4 # video file
|
||||||
|
python3 infer.py --source 0 # live USB camera
|
||||||
|
python3 infer.py --source csi # live CSI camera
|
||||||
|
python3 infer.py --source 0 --no-display # camera over SSH
|
||||||
|
```
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
# 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:
|
||||||
|
|
||||||
|
```python
|
||||||
|
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`:
|
||||||
|
|
||||||
|
```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:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from google.colab import drive
|
||||||
|
drive.mount('/content/drive')
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install Ultralytics and verify the GPU:
|
||||||
|
|
||||||
|
```python
|
||||||
|
!pip install -U ultralytics
|
||||||
|
!nvidia-smi
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Unzip the dataset:
|
||||||
|
|
||||||
|
```python
|
||||||
|
!unzip -q /content/drive/MyDrive/watch_dataset.zip -d /content/dataset
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 Train the YOLO26 Model
|
||||||
|
|
||||||
|
```python
|
||||||
|
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
|
||||||
|
|
||||||
|
```python
|
||||||
|
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
|
||||||
|
|
||||||
|
```python
|
||||||
|
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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Create the project folder and a virtual environment (system site-packages keeps NVIDIA's Jetson PyTorch / TensorRT):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Install dependencies (use the PyTorch / Ultralytics versions compatible with your JetPack):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install ultralytics
|
||||||
|
```
|
||||||
|
|
||||||
|
5. (Optional) Maximize performance:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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**.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 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
|
||||||
|
```
|
||||||
+161
@@ -0,0 +1,161 @@
|
|||||||
|
# X-ray Vision-Language Model on Jetson Orin Nano
|
||||||
|
|
||||||
|
A fine-tuned Qwen2.5-VL-3B-Instruct that reads an X-ray image and returns a text description. It runs on the NVIDIA Jetson Orin Nano (8 GB) using llama.cpp with GPU acceleration.
|
||||||
|
|
||||||
|
> **Disclaimer:** This is a research / learning project. The output is **not** a medical diagnosis and must not be used for clinical decisions.
|
||||||
|
|
||||||
|
## 1. Overview
|
||||||
|
|
||||||
|
- **Input:** one X-ray image (jpg or png)
|
||||||
|
- **Output:** text description / findings printed in the terminal
|
||||||
|
- **Model:** Qwen2.5-VL-3B-Instruct, fine-tuned with LoRA on the Unsloth Radiology Mini dataset
|
||||||
|
- **Format:** GGUF. The language model is quantized to Q4_K_M (about 2 GB). The vision encoder (mmproj) is kept at F16.
|
||||||
|
- **Runtime:** llama.cpp (`llama-server`) with CUDA on the Jetson GPU
|
||||||
|
- **Client:** `xray_infer.py`, a small Python script that resizes the image and sends it to the local server
|
||||||
|
|
||||||
|
## 2. How the model was prepared (already done)
|
||||||
|
|
||||||
|
1. Fine-tuning in Google Colab with Unsloth. The result was a LoRA adapter (`adapter_model.safetensors`, about 160 MB), not a full model.
|
||||||
|
2. The LoRA adapter was merged into the full 16-bit base model `Qwen/Qwen2.5-VL-3B-Instruct`.
|
||||||
|
3. The merged model was converted to GGUF with llama.cpp:
|
||||||
|
- `xray-Q4_K_M.gguf`: language model, 4-bit
|
||||||
|
- `mmproj-xray-f16.gguf`: vision encoder / projector, 16-bit
|
||||||
|
4. Both files were copied to the Jetson.
|
||||||
|
|
||||||
|
Only these two `.gguf` files are needed on the Jetson.
|
||||||
|
|
||||||
|
## 3. Hardware and software
|
||||||
|
|
||||||
|
- **Device:** Jetson Orin Nano 8 GB
|
||||||
|
- **JetPack:** JetPack 5 (L4T R35, revision 6.5)
|
||||||
|
- **CUDA:** 11.4
|
||||||
|
- **Compiler:** gcc 9.4
|
||||||
|
- **cmake:** 4.x
|
||||||
|
- **Python:** python3 with Pillow (or OpenCV) installed
|
||||||
|
|
||||||
|
llama.cpp was built on the Jetson with CUDA enabled, GPU architecture 87.
|
||||||
|
|
||||||
|
## 4. Folder layout
|
||||||
|
|
||||||
|
```
|
||||||
|
/home/jetson/yolo_object_detection/yolo26_model/vlm_project/
|
||||||
|
├── xray_infer.py # client script (run this)
|
||||||
|
├── <your X-ray images> # put test images here
|
||||||
|
└── vlm/
|
||||||
|
├── llama.cpp/ # llama.cpp source and build
|
||||||
|
│ └── build/bin/
|
||||||
|
│ ├── llama-server # the server program
|
||||||
|
│ └── llama-mtmd-cli # one-shot image tool
|
||||||
|
├── xray_vlm_jetson_package/
|
||||||
|
│ ├── xray-Q4_K_M.gguf # language model
|
||||||
|
│ ├── mmproj-xray-f16.gguf # vision encoder
|
||||||
|
│ ├── run_jetson.sh # not used, see Notes
|
||||||
|
│ └── README.txt # package notes
|
||||||
|
└── run_xray_server.sh # not used, see Notes
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. One-time setup: build llama.cpp
|
||||||
|
|
||||||
|
Already done on this Jetson. For a fresh machine:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/yolo_object_detection/yolo26_model/vlm_project/vlm/llama.cpp
|
||||||
|
export PATH=/usr/local/cuda/bin:$PATH
|
||||||
|
cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=87 \
|
||||||
|
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc -DLLAMA_CURL=OFF -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build --config Release -j2 --target llama-mtmd-cli llama-server 2>&1 | tee build.log
|
||||||
|
```
|
||||||
|
|
||||||
|
The build takes 20 to 40 minutes. Use `-j2` so the 8 GB of RAM is not exhausted.
|
||||||
|
|
||||||
|
## 6. How to run
|
||||||
|
|
||||||
|
You need two terminals.
|
||||||
|
|
||||||
|
**Terminal 1: start the model server and leave it open**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pkill llama-server
|
||||||
|
cd ~/yolo_object_detection/yolo26_model/vlm_project/vlm/xray_vlm_jetson_package
|
||||||
|
../llama.cpp/build/bin/llama-server -m xray-Q4_K_M.gguf --mmproj mmproj-xray-f16.gguf \
|
||||||
|
-ngl 99 -c 2048 --host 127.0.0.1 --port 8080
|
||||||
|
```
|
||||||
|
|
||||||
|
Wait about one minute until the logs say the server is listening.
|
||||||
|
|
||||||
|
**Terminal 2: run an image**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/yolo_object_detection/yolo26_model/vlm_project
|
||||||
|
python3 xray_infer.py YOUR_IMAGE.jpg
|
||||||
|
```
|
||||||
|
|
||||||
|
With a custom question and smaller image size:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 xray_infer.py YOUR_IMAGE.jpg --prompt "Describe this X-ray and report any findings." --size 448
|
||||||
|
```
|
||||||
|
|
||||||
|
**To stop:** press Ctrl+C in Terminal 1, or run `pkill llama-server`.
|
||||||
|
|
||||||
|
## 7. Options of `xray_infer.py`
|
||||||
|
|
||||||
|
- `image`: path to the X-ray image (required)
|
||||||
|
- `--prompt TEXT`: question sent to the model. Default: `Describe this X-ray image and report any findings.`
|
||||||
|
- `--size N`: longest image side in pixels, default 448. Smaller is faster, larger keeps more detail.
|
||||||
|
- `--max-tokens N`: maximum length of the answer, default 200
|
||||||
|
- `--port N`: server port, default 8080
|
||||||
|
|
||||||
|
The script prints the answer, then a line with the time taken, the number of prompt tokens and the number of generated tokens.
|
||||||
|
|
||||||
|
If the server is not running, the script tries to start it in the background and writes its log to `vlm/server.log`. It is more reliable to start the server yourself as shown in section 6.
|
||||||
|
|
||||||
|
## 8. One-shot mode (no server, no script)
|
||||||
|
|
||||||
|
Useful for a quick test. Stop any server first.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pkill llama-server
|
||||||
|
cd ~/yolo_object_detection/yolo26_model/vlm_project/vlm
|
||||||
|
./llama.cpp/build/bin/llama-mtmd-cli \
|
||||||
|
-m xray_vlm_jetson_package/xray-Q4_K_M.gguf \
|
||||||
|
--mmproj xray_vlm_jetson_package/mmproj-xray-f16.gguf \
|
||||||
|
--image ../YOUR_IMAGE.jpg \
|
||||||
|
-p "Describe this X-ray image and report any findings." \
|
||||||
|
-ngl 99 -c 4096 -n 200 --temp 0
|
||||||
|
```
|
||||||
|
|
||||||
|
The model reloads on every run, so each run is slow.
|
||||||
|
|
||||||
|
## 9. Tips for speed
|
||||||
|
|
||||||
|
- Keep the server running between images. Loading the model is the slowest step.
|
||||||
|
- Use a smaller `--size`, but stay close to the image size used in training so accuracy does not drop.
|
||||||
|
- Run these once per boot for maximum performance:
|
||||||
|
```bash
|
||||||
|
sudo nvpmodel -m 0
|
||||||
|
sudo jetson_clocks
|
||||||
|
```
|
||||||
|
- Close other heavy programs. Do not run the live-camera VLM or any other `llama-server` at the same time as this one. Two models do not fit in 8 GB of memory.
|
||||||
|
- Keep `--max-tokens` small and the prompt short.
|
||||||
|
|
||||||
|
## 10. Troubleshooting
|
||||||
|
|
||||||
|
- **No such file or directory:** Check the folder you are in and the file name. Use `ls` to list files. The image name must include its extension.
|
||||||
|
- **Image not found:** Give the correct path to the image, or the full path.
|
||||||
|
- **Model file not found:** The two `.gguf` files must be in `xray_vlm_jetson_package`. Check the paths at the top of `xray_infer.py`.
|
||||||
|
- **Server does not start, or the script says the server did not start:** Run the server manually (section 6) and read the error. Check that no other `llama-server` is running (`pkill llama-server`). Check free memory with `free -h`.
|
||||||
|
- **Out of memory:** Close other programs, stop other model servers, lower `--size`.
|
||||||
|
- **Answers look wrong or unrelated to X-rays:** Make sure the server is running the X-ray model files from `xray_vlm_jetson_package` and not an older model from another project. Use a prompt similar to the one used in training.
|
||||||
|
- **Port already in use:** Run `pkill llama-server`, then start the server again.
|
||||||
|
- **llama.cpp build fails:** Send the last 20 lines of `build.log`. JetPack 5 uses CUDA 11.4, which newer llama.cpp versions may not fully support. JetPack 6 (CUDA 12) is the reliable option.
|
||||||
|
|
||||||
|
## 11. Notes
|
||||||
|
|
||||||
|
- `run_jetson.sh` in the package looks for llama.cpp in the home folder, which is not where it lives here. Use the commands in section 6 instead.
|
||||||
|
- `run_xray_server.sh` in the `vlm` folder points to the `.gguf` files in the `vlm` folder, but they are in `xray_vlm_jetson_package`. Fix the paths before using it, or use the commands in section 6.
|
||||||
|
- Always check results on a test set of X-ray images before relying on the model. The quantized model can differ slightly from the original.
|
||||||
|
|
||||||
|
## 12. Rebuilding the model files
|
||||||
|
|
||||||
|
If the model is fine-tuned again, repeat section 2: merge the new LoRA adapter into the full base model, convert to GGUF, quantize the language model to Q4_K_M, and copy the two new `.gguf` files into `xray_vlm_jetson_package` on the Jetson. Nothing else changes.
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
# YOLO26: 8 Computer Vision Tasks on Images (Jetson Orin Nano)
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Run 8 YOLO26 computer vision tasks on a single input image using Python.
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
One script runs the YOLO26 model family on one image and saves every result into a `results/` folder. Each task loads its own YOLO26 nano model, runs it once on the image and saves an annotated image or files.
|
||||||
|
|
||||||
|
Tasks in the script:
|
||||||
|
|
||||||
|
1. Detection: boxes, class names and confidence.
|
||||||
|
2. Tracking: runs the tracker on a single image. With only one frame there is no time dimension, so IDs do not persist. Use the video version for real tracking.
|
||||||
|
3. Segmentation: pixel-level masks.
|
||||||
|
4. Pose estimation: 17 human keypoints and skeleton (needs a person in the image).
|
||||||
|
5. Classification: one label for the whole image with probability.
|
||||||
|
6. ROI extraction: crops each detected box out of the image and saves each crop.
|
||||||
|
7. Depth estimation: native YOLO26 depth model, saved as a colorized depth image plus the raw depth array.
|
||||||
|
8. OBB (oriented bounding boxes): rotated boxes (needs aerial or satellite style images).
|
||||||
|
|
||||||
|
## Hardware and Software
|
||||||
|
|
||||||
|
- Device: NVIDIA Jetson Orin Nano (JetPack with CUDA and TensorRT)
|
||||||
|
- Language: Python 3
|
||||||
|
- Libraries: ultralytics, opencv-python, numpy
|
||||||
|
- Input: one image such as `test.jpg` in the same folder as the script
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install -U ultralytics
|
||||||
|
```
|
||||||
|
|
||||||
|
On Jetson, install the JetPack-matched PyTorch and torchvision builds first (see the Jetson guide in the references). Model weights download automatically on first run, so the first run needs internet.
|
||||||
|
|
||||||
|
## Folder Layout
|
||||||
|
|
||||||
|
```
|
||||||
|
your_folder/
|
||||||
|
yolo26_8_tasks_image.py (rename to match your script file name)
|
||||||
|
test.jpg (your input image)
|
||||||
|
results/ (created automatically)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Command to Run
|
||||||
|
|
||||||
|
```
|
||||||
|
python3 yolo26_8_tasks_image.py
|
||||||
|
```
|
||||||
|
|
||||||
|
To use a different image, change the image path variable at the top of the script.
|
||||||
|
|
||||||
|
## Models Used
|
||||||
|
|
||||||
|
- Task 1, 2 and 6: `yolo26n.pt` (detection, COCO 80 classes)
|
||||||
|
- Task 3: `yolo26n-seg.pt` (instance segmentation)
|
||||||
|
- Task 4: `yolo26n-pose.pt` (17 human keypoints)
|
||||||
|
- Task 5: `yolo26n-cls.pt` (ImageNet 1000 classes)
|
||||||
|
- Task 7: `yolo26n-depth.pt` (per-pixel metric depth in meters)
|
||||||
|
- Task 8: `yolo26n-obb.pt` (DOTA aerial classes)
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. The script checks that the image exists and loads it.
|
||||||
|
2. Each task runs in its own `try/except`, so if one task fails the others still run.
|
||||||
|
3. For each task the model is called on the image and `result.plot()` gives the annotated image, which is saved to `results/`.
|
||||||
|
4. ROI extraction takes the detection boxes and crops each one from the original image.
|
||||||
|
5. Depth estimation reads the per-pixel depth map in meters, applies a color map and saves it as an image. It also saves the raw depth values as a `.npy` file.
|
||||||
|
|
||||||
|
## Output Files (inside `results/`)
|
||||||
|
|
||||||
|
These are the expected names. Your script may use slightly different names, so match them to what is in your folder.
|
||||||
|
|
||||||
|
- `1_detection.jpg` : detection result
|
||||||
|
- `2_tracking.jpg` : tracking result (single frame)
|
||||||
|
- `3_segmentation.jpg` : segmentation result
|
||||||
|
- `4_pose.jpg` : pose result
|
||||||
|
- `5_classification.jpg` : classification result with label
|
||||||
|
- `6_roi_crops/` : cropped objects, one image per detected box
|
||||||
|
- `7_depth.png` : colorized depth map
|
||||||
|
- `7_depth.npy` : raw depth values in meters
|
||||||
|
- `8_obb.jpg` : OBB result
|
||||||
|
|
||||||
|
## Sample Output (add your screenshots here)
|
||||||
|
|
||||||
|
Copy the result images into an `images` folder next to this README and update the names below.
|
||||||
|
|
||||||
|
Input image:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Detection:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Tracking:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Segmentation:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Pose estimation:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Classification:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
ROI crops:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Depth estimation:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
OBB:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
- [ ] Each finished task prints `Saved:` with its path.
|
||||||
|
- [ ] `results/` contains one output per task.
|
||||||
|
- [ ] Detection boxes sit on the right objects with sensible labels.
|
||||||
|
- [ ] Segmentation masks follow the object shape.
|
||||||
|
- [ ] Pose shows a skeleton on each person (only if the image has a person).
|
||||||
|
- [ ] Classification shows one label with a probability.
|
||||||
|
- [ ] ROI crops folder has one image per detected object.
|
||||||
|
- [ ] Depth image shows near and far areas in clearly different colors.
|
||||||
|
- [ ] OBB shows rotated boxes (only for aerial style images).
|
||||||
|
|
||||||
|
## Notes and Limitations
|
||||||
|
|
||||||
|
- Tracking on one image cannot keep IDs across frames. It is only useful as a demo of the output format. Use the video script for real tracking.
|
||||||
|
- Pose finds human keypoints only. With no person in the image the output has no skeleton.
|
||||||
|
- OBB is trained on aerial and satellite classes, so everyday photos usually return no boxes. Test it with aerial images.
|
||||||
|
- Classification expects one main subject. If the image has many objects the label is only a rough guess.
|
||||||
|
- ROI is not a separate YOLO model. It crops the detected boxes from the original image.
|
||||||
|
|
||||||
|
## Optional: Faster Inference with TensorRT
|
||||||
|
|
||||||
|
```
|
||||||
|
yolo export model=yolo26n.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then replace `YOLO("yolo26n.pt")` with `YOLO("yolo26n.engine")`.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- Image not found: put the image in the script folder or fix the path in the script.
|
||||||
|
- Empty results for pose or OBB: use an image with a person (pose) or an aerial image (OBB).
|
||||||
|
- Out of memory on Jetson: close other apps or run one task at a time.
|
||||||
|
- Slow first run: weights download and the model warms up on the first call.
|
||||||
|
- Window does not open over SSH: this script saves files, so open the images from the `results/` folder instead.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Ultralytics YOLO26 models](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [Object detection task](https://docs.ultralytics.com/tasks/detect/)
|
||||||
|
- [Object tracking mode](https://docs.ultralytics.com/modes/track/)
|
||||||
|
- [Instance segmentation task](https://docs.ultralytics.com/tasks/segment/)
|
||||||
|
- [Pose estimation task](https://docs.ultralytics.com/tasks/pose/)
|
||||||
|
- [Image classification task](https://docs.ultralytics.com/tasks/classify/)
|
||||||
|
- [Oriented bounding boxes (OBB) task](https://docs.ultralytics.com/tasks/obb/)
|
||||||
|
- [Depth estimation task](https://docs.ultralytics.com/tasks/depth/)
|
||||||
|
- [Predict mode](https://docs.ultralytics.com/modes/predict/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [Ultralytics on PyPI](https://pypi.org/project/ultralytics/)
|
||||||
|
- [OpenCV image reading and writing](https://docs.opencv.org/4.x/db/deb/tutorial_display_image.html)
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
# YOLO26: 8 Computer Vision Tasks on Video (Jetson Orin Nano)
|
||||||
|
|
||||||
|
## Task Title
|
||||||
|
|
||||||
|
Run 8 YOLO26 computer vision tasks on a single input video using Python.
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
One script runs the YOLO26 model family on one video file (`ai_video.mp4`) and saves every result into a `results/` folder. Each task loads its own YOLO26 nano model, processes the video frame by frame (streaming, so memory stays low on the Jetson) and writes an annotated output video or files.
|
||||||
|
|
||||||
|
Tasks in the script:
|
||||||
|
|
||||||
|
1. Detection: boxes, class names and confidence on every frame, saved as a video.
|
||||||
|
2. Tracking: real tracking, object IDs persist across frames, saved as a video.
|
||||||
|
3. Segmentation: pixel-level masks on every frame, saved as a video.
|
||||||
|
4. Pose estimation: skipped by default (code kept but commented out).
|
||||||
|
5. Classification: top-1 label per frame overlaid on the video, plus a text log.
|
||||||
|
6. ROI extraction: crops each detected box out of sampled frames and saves each crop as an image.
|
||||||
|
7. Depth estimation: native YOLO26 depth model, saved as a colorized depth video plus raw depth arrays.
|
||||||
|
8. OBB (oriented bounding boxes): skipped by default (code kept but commented out).
|
||||||
|
|
||||||
|
## Hardware and Software
|
||||||
|
|
||||||
|
- Device: NVIDIA Jetson Orin Nano (JetPack with CUDA and TensorRT)
|
||||||
|
- Language: Python 3
|
||||||
|
- Libraries: ultralytics, opencv-python, numpy
|
||||||
|
- Input: `ai_video.mp4` in the same folder as the script
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install -U ultralytics
|
||||||
|
```
|
||||||
|
|
||||||
|
On Jetson, install the JetPack-matched PyTorch and torchvision builds first (see the Jetson guide in the references). Model weights download automatically on first run, so the first run needs internet.
|
||||||
|
|
||||||
|
## Folder Layout
|
||||||
|
|
||||||
|
```
|
||||||
|
your_folder/
|
||||||
|
yolo26_8_tasks_video.py (rename to match your script file name)
|
||||||
|
ai_video.mp4
|
||||||
|
results/ (created automatically)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Command to Run
|
||||||
|
|
||||||
|
```
|
||||||
|
python3 yolo26_8_tasks_video.py
|
||||||
|
```
|
||||||
|
|
||||||
|
To use a different video, change `VIDEO_PATH` at the top of the script.
|
||||||
|
|
||||||
|
## Models Used
|
||||||
|
|
||||||
|
- Task 1 and 2 and 6: `yolo26n.pt` (detection, COCO 80 classes)
|
||||||
|
- Task 3: `yolo26n-seg.pt` (instance segmentation)
|
||||||
|
- Task 4 (optional): `yolo26n-pose.pt` (17 human keypoints)
|
||||||
|
- Task 5: `yolo26n-cls.pt` (ImageNet 1000 classes)
|
||||||
|
- Task 7: `yolo26n-depth.pt` (per-pixel metric depth in meters, run at imgsz=768)
|
||||||
|
- Task 8 (optional): `yolo26n-obb.pt` (DOTA aerial classes)
|
||||||
|
|
||||||
|
## Settings You Can Change
|
||||||
|
|
||||||
|
- `VIDEO_PATH = "ai_video.mp4"` : input video
|
||||||
|
- `OUT_DIR = "results"` : folder for all outputs
|
||||||
|
- `ROI_FRAME_STRIDE = 15` : save ROI crops every 15th frame
|
||||||
|
- `DEPTH_NPY_STRIDE = 30` : save a raw depth `.npy` file every 30th frame
|
||||||
|
- `imgsz=768` in the depth call : depth model input size; lower it if the Jetson runs out of memory
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. The script checks that the video exists and reads its FPS, width, height and frame count.
|
||||||
|
2. Each task runs inside its own `try/except`, so if one task fails the others still run and the failure is printed as `[n - Task] FAILED`.
|
||||||
|
3. Detection, tracking, segmentation and classification call the model with `stream=True`, read each result and write `result.plot()` to an output video.
|
||||||
|
4. Tracking uses `track(..., persist=True)` so IDs stay the same across frames.
|
||||||
|
5. ROI extraction reuses the detection results from Task 1 and crops boxes only on sampled frames, because a full video would create thousands of files.
|
||||||
|
6. Depth estimation reads `result.depth.data` (a float32 map in meters), normalizes it, applies the MAGMA color map and writes a colorized video. It prints the minimum and maximum depth across the clip.
|
||||||
|
|
||||||
|
## Output Files (inside `results/`)
|
||||||
|
|
||||||
|
- `1_detection.mp4` : detection video
|
||||||
|
- `2_tracking.mp4` : tracking video with persistent IDs
|
||||||
|
- `3_segmentation.mp4` : segmentation video
|
||||||
|
- `5_classification.mp4` : per-frame classification video
|
||||||
|
- `5_classification_log.txt` : one line per frame with the top-1 label and confidence
|
||||||
|
- `6_roi_crops/` : cropped objects, named like `frame15_roi0_person.png`
|
||||||
|
- `7_depth.mp4` : colorized depth video
|
||||||
|
- `7_depth_raw/` : raw depth arrays like `frame30.npy` (meters)
|
||||||
|
|
||||||
|
## Sample Output (add your screenshots here)
|
||||||
|
|
||||||
|
Save one frame from each output video into an `images` folder and update the names below.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Verify the Output
|
||||||
|
|
||||||
|
- [ ] The console prints the video size, FPS and frame count at the start.
|
||||||
|
- [ ] Each finished task prints `Saved:` with its path.
|
||||||
|
- [ ] `results/` contains the videos, the log, the crops folder and the depth folder.
|
||||||
|
- [ ] In `2_tracking.mp4` the same object keeps the same ID while it moves.
|
||||||
|
- [ ] In `3_segmentation.mp4` the colored masks follow object shapes.
|
||||||
|
- [ ] In `7_depth.mp4` nearer objects and farther objects have clearly different colors.
|
||||||
|
- [ ] The final line prints `Done. Check the 'results' folder for all saved outputs.`
|
||||||
|
|
||||||
|
## Notes and Limitations
|
||||||
|
|
||||||
|
- Pose (task 4): the pose model finds human keypoints. If the video has no person, every frame returns nothing. Uncomment the block and use footage with people.
|
||||||
|
- OBB (task 8): the OBB model is trained on aerial and satellite classes (planes, ships, vehicles, storage tanks). On everyday scenes it returns nothing. Uncomment the block and use aerial footage.
|
||||||
|
- Classification (task 5): classification expects one main subject per frame. With many objects in view the top-1 label is only a rough per-frame guess, not a scene description.
|
||||||
|
- ROI (task 6): this is not a separate YOLO model. It crops the detected boxes from the original frame.
|
||||||
|
|
||||||
|
## Optional: Faster Inference with TensorRT
|
||||||
|
|
||||||
|
Export a model once and use the engine file in the script:
|
||||||
|
|
||||||
|
```
|
||||||
|
yolo export model=yolo26n.pt format=engine half=True
|
||||||
|
```
|
||||||
|
|
||||||
|
Then replace `YOLO("yolo26n.pt")` with `YOLO("yolo26n.engine")`.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- `Could not open 'ai_video.mp4'`: put the video in the same folder as the script or fix `VIDEO_PATH`.
|
||||||
|
- Output video is empty or cannot be played: install a player that supports `mp4v`, or change the codec in `open_writer`.
|
||||||
|
- Out of memory on Jetson: close other apps, lower `imgsz` for depth, or run one task at a time.
|
||||||
|
- Low speed: run `sudo nvpmodel -m 0` and `sudo jetson_clocks`, or export to TensorRT.
|
||||||
|
- Weights fail to download: connect to the internet for the first run, or copy the `.pt` files next to the script.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Ultralytics YOLO26 models](https://docs.ultralytics.com/models/yolo26/)
|
||||||
|
- [Object detection task](https://docs.ultralytics.com/tasks/detect/)
|
||||||
|
- [Object tracking mode](https://docs.ultralytics.com/modes/track/)
|
||||||
|
- [Instance segmentation task](https://docs.ultralytics.com/tasks/segment/)
|
||||||
|
- [Pose estimation task](https://docs.ultralytics.com/tasks/pose/)
|
||||||
|
- [Image classification task](https://docs.ultralytics.com/tasks/classify/)
|
||||||
|
- [Oriented bounding boxes (OBB) task](https://docs.ultralytics.com/tasks/obb/)
|
||||||
|
- [Depth estimation task](https://docs.ultralytics.com/tasks/depth/)
|
||||||
|
- [Predict mode (streaming inference)](https://docs.ultralytics.com/modes/predict/)
|
||||||
|
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
|
||||||
|
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
|
||||||
|
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
|
||||||
|
- [Ultralytics on PyPI](https://pypi.org/project/ultralytics/)
|
||||||
|
- [OpenCV VideoWriter docs](https://docs.opencv.org/4.x/dd/d9e/classcv_1_1VideoWriter.html)
|
||||||
Reference in New Issue
Block a user