Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

YOLOv8 Object Detection

A simple tool to detect objects in images, videos, and webcam feeds using YOLOv8 models (.onnx or .pt files).

Quick Start

  1. Install dependencies:

    chmod +x setup.sh
    ./setup.sh venv gpu  # or ./setup.sh venv cpu
    source object-detect-env/bin/activate
  2. 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.

Project Structure

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

Installation

Option 1: Python venv (Recommended for most users)

Automatic Setup

chmod +x setup.sh  # Linux/macOS
./setup.sh venv gpu  # or ./setup.sh venv cpu
source object-detect-env/bin/activate

For Windows:

.\setup.ps1 -EnvType venv -Runtime gpu  # or -Runtime cpu
.\object-detect-env\Scripts\Activate.ps1

Manual Setup

python3 -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.txt

Option 2: Conda (If you have Anaconda/Miniconda)

Automatic Setup

chmod +x setup.sh  # Linux/macOS
./setup.sh conda gpu  # or ./setup.sh conda cpu
conda activate object-detect-env

For Windows:

.\setup.ps1 -EnvType conda -Runtime gpu  # or -Runtime cpu
conda activate object-detect-env

Manual Setup

conda create -n object-detect-env python=3.10 -y
conda activate object-detect-env
pip install -r requirements.txt

Usage

Supports both ONNX (.onnx) and PyTorch (.pt) model files.

Image Detection

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-url for online images.
  • Add --no-show to skip displaying the result.

Video Detection

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-url for YouTube videos.
  • Add --save-output output.mp4 to save the annotated video.

Webcam Detection

python scripts/webcam_object_detection.py --model models/best.onnx
# or .pt
python scripts/webcam_object_detection.py --model models/best.pt
  • Press s to save a snapshot, q to quit.

Options

  • --conf-thres 0.5: Set confidence threshold (default 0.2-0.5)
  • --iou-thres 0.5: Set IoU threshold (default 0.3-0.5)

Model Support

  • ONNX (.onnx): Faster, optimized for inference. Requires onnxruntime.
  • PyTorch (.pt): Flexible, easy to modify. Requires ultralytics.

Place your models in the models/ folder.

Requirements

  • Python 3.10+
  • For ONNX: onnxruntime or onnxruntime-gpu
  • For PyTorch: ultralytics
  • GPU optional (faster with CUDA)

Tips

  • 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

Troubleshooting

  • 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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages