Skip to main content

YOLOv8 + SAHI Detection Pipeline for Tiny Object Optimization

Project description

Screw Detector

[CI [PyPI [Python [License [Code style: black

YOLOv8 + SAHI Detection Pipeline for Tiny Object Optimization

A high-precision object detection system for tiny objects (screws, bolts, washers) using YOLOv8 and Slicing Aided Hyper Inference (SAHI).

Features

  • High-Precision Detection: Optimized for detecting tiny objects (10-15px) in high-resolution images
  • SAHI Integration: Native slicing logic to recover small objects during inference
  • Multiple Inference Strategies: Baseline YOLOv8 and SAHI-enhanced detection
  • Easy-to-Use CLI: Command-line tools for training, evaluation, and deployment
  • Production Ready: Export models to ONNX and OpenVINO for edge deployment
  • Comprehensive Testing: Full test suite with pytest

Installation

From PyPI

pip install screw-detector

From Source

git clone https://github.com/3bsalam-1/Screw-Detector.git
cd Screw-Detector
pip install -e .

Development Installation

pip install -e ".[dev]"
pre-commit install

Quick Start

Training a Model

# Train baseline model
screw-train --model yolov8s.pt --data data/configs/data.yaml --epochs 150

# Train on sliced dataset
screw-train --model yolov8s.pt --sliced-data --epochs 150

Running Inference

# Baseline inference
screw-demo --model models/best.pt --input image.jpg --strategy baseline

# SAHI inference
screw-demo --model models/best.pt --input image.jpg --strategy sahi

# Compare strategies
screw-demo --model models/best.pt --input image.jpg --strategy compare

Evaluating Models

# Evaluate with both strategies
screw-evaluate --model models/best.pt --data data/configs/data.yaml --strategy both --save-plots

Exporting Models

# Export to ONNX
screw-export --model models/best.pt --format onnx

# Export to OpenVINO with INT8 quantization
screw-export --model models/best.pt --format openvino --int8

# Export to all formats
screw-export --model models/best.pt --format all

Project Structure

screw-detector/
├── .github/              # CI/CD workflows and templates
├── data/                 # Dataset and configurations
│   ├── configs/          # Data configuration files
│   ├── raw/              # Original dataset
│   └── processed/        # Processed/sliced dataset
├── docs/                 # Documentation
├── notebooks/             # Jupyter notebooks
├── src/                  # Source code
│   ├── screw_detector/   # Package modules
│   └── scripts/          # CLI scripts
├── tests/                # Unit tests
├── models/               # Trained models
└── results/              # Training results

Dataset

This project uses a custom-annotated dataset of bolts and washers.

Classes

  • Bolt
  • Bottle
  • Washer

Performance Benchmarks

Based on internal evaluation:

Strategy Precision Recall F1-Score Avg Time (ms)
Baseline (1280 Resize) 88.5% 90.7% 89.6% ~85ms
Optimized SAHI (1280) 92.4% 94.2% 93.3% ~450ms
Sliced SAHI (640) 85.1% 87.8% 86.4% ~220ms

Size-Based Recall Recovery

SAHI significantly outperforms standard inference for the most challenging objects:

  • Small (<15px): ~80.6% recovery
  • Medium (15-30px): ~94.0% recovery
  • Large (>30px): ~97.6% recovery

Documentation

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

Development Setup

# Clone the repository
git clone https://github.com/3bsalam-1/Screw-Detector.git
cd Screw-Detector

# Create a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

# Run linting
ruff check src/ tests/
black --check src/ tests/
mypy src/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this project in your research, please cite:

@software{screw_detector,
  title = {Screw Detector: YOLOv8 + SAHI Detection Pipeline for Tiny Object Optimization},
  author = {Screw Detector Team},
  year = {2024},
  url = {https://github.com/3bsalam-1/Screw-Detector}
}

Acknowledgments

Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

screw_detector-0.1.0.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

screw_detector-0.1.0-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file screw_detector-0.1.0.tar.gz.

File metadata

  • Download URL: screw_detector-0.1.0.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for screw_detector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07f92fdbd380c2f51250f68b9b1bf3a8985b62274f39216ce9e6a52c826e0deb
MD5 4bdb29247a20785ae732ad797bff1aa8
BLAKE2b-256 b342a0dd5ee6539daf3773967efaaf072e7fbe25b980d9f7bf046ca1c6182b5e

See more details on using hashes here.

File details

Details for the file screw_detector-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: screw_detector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for screw_detector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10c985a13c23d30e4518782fdd2e9f3521ecc043891c35ccc39b71c134e1500f
MD5 94054f0aa9186c22f29a491bcd458aad
BLAKE2b-256 39c5f09722ede0a3cb2a565b9757b156cfea8950504e68fe4272f1c90e8c3f06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page