A simple tool to detect objects in images, videos, and webcam feeds using YOLOv8 models (.onnx or .pt files).
-
Install dependencies:
chmod +x setup.sh ./setup.sh venv gpu # or ./setup.sh venv cpu source object-detect-env/bin/activate
-
Run detection (ONNX/.pt supported):
# Image python scripts/image_object_detection.py --model models/best.onnx --image-path your_image.jpg # or python scripts/image_object_detection.py --model models/best.pt --image-path your_image.jpg # Video python scripts/video_object_detection.py --model models/best.onnx --video-path your_video.mp4 # or python scripts/video_object_detection.py --model models/best.pt --video-path your_video.mp4 # Webcam python scripts/webcam_object_detection.py --model models/best.onnx # or python scripts/webcam_object_detection.py --model models/best.pt
That's it! The tool will detect objects and show/save the results.
ONNX_Object_Detection/
├── models/ # Your .onnx or .pt model files
├── scripts/ # Run these to detect objects
├── yolov8/ # Core detection code
├── train/ # Training configs and outputs
├── notebooks/ # Model conversion tools
├── docs/ # Detailed guides
├── setup.sh # Linux/macOS installer
├── setup.ps1 # Windows installer
├── requirements.txt # Python packages
└── README.md # This file
chmod +x setup.sh # Linux/macOS
./setup.sh venv gpu # or ./setup.sh venv cpu
source object-detect-env/bin/activateFor Windows:
.\setup.ps1 -EnvType venv -Runtime gpu # or -Runtime cpu
.\object-detect-env\Scripts\Activate.ps1python3 -m venv object-detect-env
source object-detect-env/bin/activate # Linux/macOS
# or on Windows: .\object-detect-env\Scripts\Activate.ps1
pip install -r requirements.txtchmod +x setup.sh # Linux/macOS
./setup.sh conda gpu # or ./setup.sh conda cpu
conda activate object-detect-envFor Windows:
.\setup.ps1 -EnvType conda -Runtime gpu # or -Runtime cpu
conda activate object-detect-envconda create -n object-detect-env python=3.10 -y
conda activate object-detect-env
pip install -r requirements.txtSupports both ONNX (.onnx) and PyTorch (.pt) model files.
python scripts/image_object_detection.py --model models/best.onnx --image-path path/to/image.jpg
# or .pt
python scripts/image_object_detection.py --model models/best.pt --image-path path/to/image.jpg- Use
--image-urlfor online images. - Add
--no-showto skip displaying the result.
python scripts/video_object_detection.py --model models/best.onnx --video-path path/to/video.mp4
# or .pt
python scripts/video_object_detection.py --model models/best.pt --video-path path/to/video.mp4- Use
--youtube-urlfor YouTube videos. - Add
--save-output output.mp4to save the annotated video.
python scripts/webcam_object_detection.py --model models/best.onnx
# or .pt
python scripts/webcam_object_detection.py --model models/best.pt- Press
sto save a snapshot,qto quit.
--conf-thres 0.5: Set confidence threshold (default 0.2-0.5)--iou-thres 0.5: Set IoU threshold (default 0.3-0.5)
- ONNX (.onnx): Faster, optimized for inference. Requires
onnxruntime. - PyTorch (.pt): Flexible, easy to modify. Requires
ultralytics.
Place your models in the models/ folder.
- Python 3.10+
- For ONNX:
onnxruntimeoronnxruntime-gpu - For PyTorch:
ultralytics - GPU optional (faster with CUDA)
-
Convert models: Use
notebooks/Convert_YOLOv8_to_ONNX.ipynb -
Train models: Check
train/data/ -
Outputs saved to
outputs/folder automatically -
For help:
python scripts/script_name.py --help -
Convert models: Use
notebooks/Convert_YOLOv8_to_ONNX.ipynb -
Train models: Check
train/data/ -
Outputs saved to
outputs/folder automatically -
For help:
python scripts/script_name.py --help
- Import error? Run
pip install -r requirements.txt - No GPU? Use CPU version:
pip install onnxruntime(not onnxruntime-gpu) - Model not found? Check path in
models/folder
For more details, see docs/ folder.