VisionStock is an end-to-end computer vision system for automated retail shelf inventory detection and analysis. The system uses fine-tuned YOLOv8 object detection to identify products on shelves, compares detections against planogram expectations, and provides real-time inventory analytics through a Streamlit dashboard.
This project demonstrates the research question: "Does fine-tuning YOLOv8 on a small, category-specific dataset significantly improve product detection performance on retail shelf images?"
- β
Two-Study Evaluation: Comprehensive baseline vs fine-tuned comparison
- Study 1: Different datasets (SKU-110K baseline, Custom fine-tuned)
- Study 2: Same dataset (Custom baseline, Custom fine-tuned)
- β Baseline Evaluation: Pre-trained YOLOv8n on SKU-110K samples
- β Fine-Tuning: Custom dataset training (34 classes, 111 images) - Trained on Google Colab
- β Production Model: Trained model hosted on Ultralytics Hub (50 epochs, mAP50: 4.13%)
- β REST API: FastAPI backend for image upload and detection
- β Database Integration: PostgreSQL for storing detections and planograms
- β SQL Analytics: Automated discrepancy detection (missing, low stock, misplaced)
- β Interactive Dashboard: Streamlit UI with 8 sections including two-study comparison
- β Docker Deployment: Ready for local and cloud deployment
- β GCP Cloud Run Ready: Pre-configured for Google Cloud Platform deployment
- β₯10% mAP improvement after fine-tuning vs. baseline
- 85-90% precision/recall on evaluation images
- β€5% discrepancy error for stock gap identification
- β€2 seconds end-to-end latency per image
- Python 3.8+
- PostgreSQL 12+
- pip or conda
# 1. Clone repository
git clone <repository-url>
cd VisionStock
# 2. Install dependencies
pip install -r requirements.txt
# 3. Set up database
createdb shelf_sense_db
# 4. Configure environment
cp env_template.txt .env
# Edit .env with your database credentials
# 5. Initialize database
python backend/init_database.pySee INSTALLATION.md for detailed setup instructions.
Option 1: Docker (Recommended)
docker-compose up -dOption 2: Manual Start
Start FastAPI Backend:
cd backend
uvicorn main:app --reload --host 0.0.0.0 --port 8000Start Streamlit Dashboard (in new terminal):
streamlit run dashboard/app.pyAccess Services:
- API: http://localhost:8000/docs
- Dashboard: http://localhost:8501
Local Docker:
./scripts/deploy.shGCP Cloud Run (Recommended for Large Images):
# Quick deploy
./scripts/deploy_gcp.sh
# Or see detailed guide
# See docs/GCP_DEPLOYMENT.md for step-by-step instructionsProduction Model: The system uses the trained model from Ultralytics Hub by default. No local model files needed!
VisionStock/
βββ backend/ # FastAPI application
β βββ main.py # API routes
β βββ config.py # Configuration
β βββ db_config.py # Database models
β βββ sql/ # SQL scripts
βββ dashboard/ # Streamlit UI
β βββ app.py # Dashboard interface
βββ scripts/ # All scripts organized
β βββ notebooks/ # Evaluation scripts
β βββ training/ # Training scripts
βββ utils/ # Utility functions
βββ results/ # Evaluation results
β βββ study1_comparison.json
β βββ study2_comparison.json
β βββ FINAL_TWO_STUDY_REPORT.md
βββ data/ # Dataset configs (YAML only)
βββ models/ # Model files
βββ docs/ # Documentation
βββ tests/ # Test scripts
See PROJECT_STRUCTURE.md for complete structure.
- PROJECT_STRUCTURE.md - Complete directory structure
- docs/GCP_DEPLOYMENT.md - GCP Cloud Run deployment guide
POST /api/detect- Upload image and detect objectsGET /api/detections- Get detection records
POST /api/planograms- Create planogram entryGET /api/planograms- Get planogram records
POST /api/analyze- Compare detections with planogramGET /api/discrepancies- Get discrepancy recordsGET /api/summary- Get summary statistics
See USAGE.md for detailed API examples.
python scripts/notebooks/baseline_evaluation.pypython scripts/notebooks/fine_tuning.pyThe model was trained on Google Colab and synced to Ultralytics Hub. For local training with Hub:
python scripts/training/train_with_hub.pyNote: The production model is already trained and available on Ultralytics Hub.
Study 1: Different Datasets (As Per Original Proposal)
- Baseline: COCO pre-trained on SKU-110K dataset
- Fine-Tuned: Custom Retail Dataset
- Results: See
results/study1_comparison.json
Study 2: Same Dataset (Before/After Fine-Tuning)
- Baseline: COCO pre-trained on Custom Retail Dataset
- Fine-Tuned: Custom Retail Dataset
- Results: See
results/study2_comparison.json
Training results and metrics are stored in results/:
study1_comparison.json- Study 1 metricsstudy2_comparison.json- Study 2 metricsFINAL_TWO_STUDY_REPORT.md- Comprehensive comparison report
- Computer Vision: Ultralytics YOLOv8
- Backend: FastAPI, SQLAlchemy
- Database: PostgreSQL
- Frontend: Streamlit
- Training: Ultralytics Hub
[Add your license here]
[Add contributors here]
- Ultralytics for YOLOv8
- Roboflow for dataset annotation tools
- Hugging Face for KanOps dataset