Update README.md
This commit is contained in:
@@ -1,130 +1,107 @@
|
|||||||
============================================================
|
# Task 01: Object Detection Using Python
|
||||||
TASK 01 OF 8 : OBJECT DETECTION USING PYTHON
|
|
||||||
============================================================
|
## Task Title
|
||||||
|
|
||||||
TASK TITLE
|
|
||||||
Object Detection Using Python
|
Object Detection Using Python
|
||||||
|
|
||||||
DESCRIPTION
|
## Description
|
||||||
Implement and test the 01_detection.py script to detect objects in a live camera feed and draw a bounding box, class name and confidence score around each one.
|
|
||||||
|
|
||||||
PLATFORM
|
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.
|
||||||
NVIDIA Jetson Orin Nano, YOLO26 model, Python 3, OpenCV
|
|
||||||
|
|
||||||
============================================================
|
## When to Use
|
||||||
WHAT THIS SCRIPT DOES
|
|
||||||
============================================================
|
|
||||||
- Opens the webcam / camera feed
|
|
||||||
- Loads the YOLO26n detection model and warms it up with a dummy image
|
|
||||||
- Runs object detection on every frame (80 COCO classes such as person, car, chair)
|
|
||||||
- Draws a green bounding box, class name and confidence on every object
|
|
||||||
- Shows live FPS and the number of objects on screen
|
|
||||||
|
|
||||||
============================================================
|
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.
|
||||||
WHEN TO USE THIS
|
|
||||||
============================================================
|
|
||||||
Use it when you only need to know WHAT is in the frame and WHERE (as a box). It does not give object IDs, pixel-exact shapes or body pose.
|
|
||||||
|
|
||||||
============================================================
|
## Hardware and Software
|
||||||
HOW IT DIFFERS FROM THE OTHER SCRIPTS
|
|
||||||
============================================================
|
|
||||||
02_tracking.py same detection, plus a persistent ID per object
|
|
||||||
03_segmentation.py exact pixel outline instead of a box
|
|
||||||
04_pose_estimation.py body joints / keypoints for people
|
|
||||||
05_classification.py one label for the whole frame, no boxes
|
|
||||||
|
|
||||||
============================================================
|
- Device: NVIDIA Jetson Orin Nano (JetPack with CUDA and TensorRT)
|
||||||
REQUIREMENTS AND SETUP
|
- Camera: USB webcam (for example Logitech BRIO 100) at CAMERA_INDEX 0
|
||||||
============================================================
|
- Language: Python 3
|
||||||
1. Device: NVIDIA Jetson Orin Nano (JetPack installed, CUDA available)
|
- Model: YOLO26 (Ultralytics), weights `yolo26n.pt`
|
||||||
2. Camera: USB webcam (Logitech BRIO 100 or any UVC camera)
|
- Libraries: ultralytics, opencv-python, numpy
|
||||||
3. Python 3 with these packages:
|
|
||||||
pip3 install ultralytics opencv-python numpy
|
|
||||||
Note: on Jetson, install the NVIDIA-built PyTorch and torchvision
|
|
||||||
wheels for your JetPack version first, so that PyTorch uses the GPU.
|
|
||||||
See the Ultralytics NVIDIA Jetson guide in the references below.
|
|
||||||
4. Check that the camera is detected:
|
|
||||||
ls /dev/video*
|
|
||||||
v4l2-ctl --list-devices
|
|
||||||
5. Optional - get the best speed from the board before running:
|
|
||||||
sudo nvpmodel -m 0
|
|
||||||
sudo jetson_clocks
|
|
||||||
|
|
||||||
============================================================
|
## Installation
|
||||||
COMMAND TO RUN
|
|
||||||
============================================================
|
|
||||||
Open a terminal in the folder that contains the scripts and run:
|
|
||||||
|
|
||||||
|
```
|
||||||
|
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
|
python3 01_detection.py
|
||||||
|
```
|
||||||
|
|
||||||
Press Q in the video window to quit.
|
Check the camera is visible before running:
|
||||||
|
|
||||||
Run it again with the Jetson in max performance mode if FPS is low:
|
```
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
sudo nvpmodel -m 0 && sudo jetson_clocks && python3 01_detection.py
|
## 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.
|
||||||
SETTINGS YOU CAN CHANGE (top of 01_detection.py)
|
2. Open the camera with OpenCV and set the resolution (1280x720).
|
||||||
============================================================
|
3. For every frame call the model with the confidence and IoU thresholds.
|
||||||
CAMERA_INDEX which camera to open (0 = default)
|
4. Read boxes, class ids and confidences from the result and draw them with OpenCV.
|
||||||
FRAME_W/FRAME_H capture resolution (1280 x 720)
|
5. Compute and overlay FPS and the number of detected objects. Press Q to quit.
|
||||||
CONF_THRESHOLD ignore detections below this confidence (0.45)
|
|
||||||
IOU_THRESHOLD NMS threshold that removes duplicate boxes (0.45)
|
|
||||||
MODEL_WEIGHTS model file (yolo26n.pt)
|
|
||||||
|
|
||||||
============================================================
|
## Settings You Can Change
|
||||||
EXPECTED OUTPUT
|
|
||||||
============================================================
|
|
||||||
A live window titled 'YOLO - Detection' with green boxes, labels like 'person 0.87', and a yellow FPS / Objects counter in the top-left corner.
|
|
||||||
|
|
||||||
============================================================
|
Edit these values at the top of the script:
|
||||||
VERIFY THE RESULT
|
|
||||||
============================================================
|
|
||||||
Verify the script execution and validate the output:
|
|
||||||
1. The camera window opens without errors.
|
|
||||||
2. Hold a person / bottle / phone in front of the camera - a box with the right label appears.
|
|
||||||
3. The FPS counter updates continuously.
|
|
||||||
4. Pressing Q closes the window cleanly.
|
|
||||||
|
|
||||||
============================================================
|
- CAMERA_INDEX = 0 : which camera to open (0 = default)
|
||||||
TENSORRT BOOST (OPTIONAL)
|
- FRAME_W / FRAME_H = 1280 / 720 : capture resolution
|
||||||
============================================================
|
- CONF_THRESHOLD = 0.45 : ignore detections below this confidence
|
||||||
For a big speed-up on Jetson, export the model once to a TensorRT
|
- IOU_THRESHOLD = 0.45 : Non-Max-Suppression threshold that removes duplicate boxes
|
||||||
engine and point MODEL_yolo26n.pt at the generated .engine file:
|
- MODEL_WEIGHTS = yolo26n.pt : nano model, smallest and fastest, good for Jetson
|
||||||
yolo export model=yolo26n.pt format=engine half=True device=0
|
|
||||||
Then set MODEL_yolo26n.pt = 'yolo26n.engine' in the script and run it
|
|
||||||
the same way as before.
|
|
||||||
|
|
||||||
============================================================
|
## Controls
|
||||||
TROUBLESHOOTING
|
|
||||||
============================================================
|
|
||||||
- Error: could not open camera
|
|
||||||
Change CAMERA_INDEX at the top of the script (try 0, 1, 2).
|
|
||||||
Run ls /dev/video* to see which index your camera uses.
|
|
||||||
Close any other program that is using the camera.
|
|
||||||
- Window does not open / "cannot connect to display"
|
|
||||||
Run the script on the Jetson desktop, or set the display first:
|
|
||||||
export DISPLAY=:0
|
|
||||||
- Very low FPS
|
|
||||||
Make sure PyTorch uses the GPU (python3 -c "import torch; print(torch.cuda.is_available())"
|
|
||||||
should print True). Lower FRAME_W / FRAME_H, use the nano (n) model,
|
|
||||||
and export the model to TensorRT (see section TENSORRT BOOST).
|
|
||||||
- Weights file download fails
|
|
||||||
The first run downloads the weights from the internet. Connect the
|
|
||||||
Jetson to a network once, or copy the .pt file next to the script.
|
|
||||||
|
|
||||||
============================================================
|
- Press `Q` to quit the live window
|
||||||
REFERENCE LINKS
|
|
||||||
============================================================
|
|
||||||
Detection task docs: https://docs.ultralytics.com/tasks/detect/
|
|
||||||
COCO dataset (80 classes): https://docs.ultralytics.com/datasets/detect/coco/
|
|
||||||
Predict mode docs: https://docs.ultralytics.com/modes/predict/
|
|
||||||
YOLO26 model docs: https://docs.ultralytics.com/models/yolo26/
|
|
||||||
Ultralytics GitHub: https://github.com/ultralytics/ultralytics
|
|
||||||
Jetson setup guide: https://docs.ultralytics.com/guides/nvidia-jetson/
|
|
||||||
TensorRT export guide: https://docs.ultralytics.com/integrations/tensorrt/
|
|
||||||
OpenCV documentation: https://docs.opencv.org/4.x/
|
|
||||||
|
|
||||||
============================================================
|
## Verify the Output
|
||||||
END OF README - 01_detection.py
|
|
||||||
============================================================
|
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)
|
||||||
Reference in New Issue
Block a user