Skip to content

πŸ›’πŸ” PyTorch retail detective for spotting products on crowded shelves! Built for I2DL course using ResNet50 + FPN. Great for learning dense object detection, includes testing and YOLOv5 comparisons.

Notifications You must be signed in to change notification settings

KirbysGit/shelfVision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Retail Product Detection Model

A PyTorch-based object detection framework specifically designed for detecting retail products in densely packed shelf images, developed for the Introduction to Deep Learning course.

Dataset

The project uses the SKU-110K dataset, which contains retail shelf images with densely packed products. We provide two versions of the dataset via UCF OneDrive:

  1. Complete Dataset (~30GB): Download Full SKU-110K Dataset

    • Training: 8,233 images
    • Validation: 588 images
    • Test: 2,941 images
  2. Small Dataset (~4GB): Download Small SKU-110K Dataset

    • Training: 1,000 images
    • Validation: 200 images
    • Test: 100 images
    • Perfect for quick experimentation and development

Creating Your Own Small Dataset

If you have the full dataset, you can create your own small version:

# Create small dataset from full dataset
python restart/utils/create_small_dataset.py

# Optional: Customize the size
python restart/utils/create_small_dataset.py --train 500 --val 100 --test 50

This will create a new directory datasets/SKU-110K-Small with the reduced dataset.

Dataset Structure

After downloading and extracting the dataset, organize it as follows:

datasets/
β”œβ”€β”€ SKU-110K/
β”‚   β”œβ”€β”€ images/
β”‚   β”‚   β”œβ”€β”€ train/          # Training images
β”‚   β”‚   β”œβ”€β”€ val/            # Validation images
β”‚   β”‚   └── test/           # Test images
β”‚   └── annotations/
β”‚       β”œβ”€β”€ annotations_train.csv
β”‚       β”œβ”€β”€ annotations_val.csv
β”‚       └── annotations_test.csv
└── sample_test/            # Sample images for quick testing

Annotation Format

The CSV files contain the following columns:

image_name, x1, y1, x2, y2, class, image_width, image_height

Where:

  • image_name: Name of the image file
  • x1, y1: Top-left corner coordinates
  • x2, y2: Bottom-right corner coordinates
  • class: Always 1 (single class detection)
  • image_width, image_height: Original image dimensions

Quick Start with Sample Data

For quick testing without downloading the full dataset:

  1. A small sample dataset is included in the repository under datasets/sample_test/
  2. Contains 10 test images with annotations
  3. Useful for testing the inference pipeline

Setting Up the Dataset

  1. Download the zip file from the OneDrive link above
  2. Extract the contents to your project directory:
# Create dataset directory
mkdir -p datasets/SKU-110K

# Extract dataset
unzip SKU-110K_Dataset.zip -d datasets/SKU-110K

# Verify structure
tree datasets/SKU-110K -L 2
  1. Verify the installation:
python restart/test/test_dataset.py

This will run basic checks to ensure the dataset is properly organized and readable.

Process For Installation

Setup Instructions

  1. Clone the repository:
git clone https://github.com/KirbysGit/I2DLproj.git
cd retail-detection
  1. Create and activate a virtual environment:
# Create virtual environment
python -m venv venv

# Activate (Windows)
.\venv\Scripts\activate

# Activate (Linux/Mac)
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Download the dataset:
    • Download from the provided OneDrive link
    • Extract to datasets/SKU-110K/
    • Ensure the following structure:

## Project Structure

i2dlproj/ β”œβ”€β”€ v1/ # Legacy version (initial baseline implementation) β”‚ β”œβ”€β”€ ... # Old source code and training pipeline β”‚ β”œβ”€β”€ restart/ # Current implementation (modular, improved architecture) β”‚ β”œβ”€β”€ model/ # Core model components: backbone, FPN, detection head, anchors β”‚ β”‚ β”œβ”€β”€ anchor_generator.py β”‚ β”‚ β”œβ”€β”€ backbone.py β”‚ β”‚ β”œβ”€β”€ detection_head.py β”‚ β”‚ β”œβ”€β”€ detector.py β”‚ β”‚ └── fpn.py β”‚ β”‚ β”‚ β”œβ”€β”€ data/ # Dataset loader and retail image preprocessing β”‚ β”‚ └── dataset.py β”‚ β”‚ β”‚ β”œβ”€β”€ utils/ # Helper functions for box operations and plotting β”‚ β”‚ β”œβ”€β”€ box_ops.py β”‚ β”‚ β”œβ”€β”€ plots.py β”‚ β”‚ └── visualize_detections.py β”‚ β”‚ β”‚ β”œβ”€β”€ train/ # Training loop and training logic β”‚ β”‚ └── trainer.py β”‚ β”‚ β”‚ β”œβ”€β”€ test/ # Unit tests for model components β”‚ β”‚ β”œβ”€β”€ test_anchor_coverage.py β”‚ β”‚ β”œβ”€β”€ test_anchor_generator.py β”‚ β”‚ β”œβ”€β”€ test_anchor_matching.py β”‚ β”‚ β”œβ”€β”€ test_box_iou.py β”‚ β”‚ β”œβ”€β”€ test_dataset.py β”‚ β”‚ β”œβ”€β”€ test_detection_head.py β”‚ β”‚ β”œβ”€β”€ test_detector.py β”‚ β”‚ β”œβ”€β”€ test_overfitting.py β”‚ β”‚ └── test_pipeline.py β”‚ β”‚ β”‚ β”œβ”€β”€ config/ # YAML configuration files for training/evaluation β”‚ β”‚ β”œβ”€β”€ testing_config.yaml β”‚ β”‚ └── training_config.yaml β”‚ β”‚ β”‚ β”œβ”€β”€ test.py # Evaluation entry point for running tests β”‚ └── compareSOTA.py # Evaluation script for benchmarking against SOTA (YOLOv5) β”‚ β”œβ”€β”€ training_runs/ # Saved training checkpoints, logs, and visualizations β”‚ └── TR_{timestamp}/ β”‚ β”œβ”€β”€ checkpoints/ β”‚ β”œβ”€β”€ visualizations/ β”‚ └── training_loss.png β”‚ β”œβ”€β”€ test_runs/ # Evaluation outputs for specific model runs β”‚ └── eval_{model}_{timestamp}/ β”‚ β”œβ”€β”€ metrics/ β”‚ β”œβ”€β”€ visualizations/ β”‚ └── eval_config.yaml β”‚ β”œβ”€β”€ comparison_results/ # YOLOv5 vs ShelfVision comparison outputs β”œβ”€β”€ checkpoints/ # Manually saved model weights β”œβ”€β”€ debug_output/ # Intermediate debug images and logs β”œβ”€β”€ test_results/ # Unit test output and logs β”œβ”€β”€ docs/ # Project documentation, slides, and notes └── requirements.txt # Python dependencies list


The project follows a modular structure where:
- `restart/`: Contains all source code and modular implementation for the latest model version
  - `model/`: Backbone, FPN, anchors, and detection logic
  - `data/`: Dataset loading and preprocessing
  - `utils/`: Visualization and box operations
  - `train/`: Core training loop logic
  - `test/`: Unit tests for model components
  - `config/`: Config files for training and testing
  - `compareSOTA.py` and `test.py`: Entry points for evaluation
- `test_runs/`: Stores model evaluation results, metrics, and visualizations
- `comparison_results/`: Output comparisons against YOLOv5 baseline models
- `training_runs/`: Contains training logs and outputs
- `debug_output/`: Debug visualizations and outputs
- `test_results/`: Test execution outputs
- `docs/`: Project documentation
- `checkpoints/`: Saved model weights and states

⚠️ **Legacy Note**: The `v1/` folder contains the original baseline version used in early development (Eval 1). 
The `restart/` directory includes the updated model logic, modular pipeline, and improvements featured in Eval 2.


## Running the Code

### Training
1. Configure training parameters:
```bash
# Edit training configuration
vim restart/config/training_config.yaml
  1. Start training:
python restart/train/trainer.py

Training outputs will be saved to training_runs/TR_{timestamp}/:

  • Model checkpoints in checkpoints/
  • Training visualizations in visualizations/
  • Loss plots and metrics in root directory

Evaluation

  1. Configure evaluation parameters:
# Edit testing configuration
vim restart/config/testing_config.yaml
  1. Run evaluation:
python restart/test.py

Evaluation outputs will be saved to test_runs/eval_{model}_{timestamp}/:

  • Detection visualizations
  • Precision-recall curves
  • IoU histograms
  • Detailed metrics summary

About

πŸ›’πŸ” PyTorch retail detective for spotting products on crowded shelves! Built for I2DL course using ResNet50 + FPN. Great for learning dense object detection, includes testing and YOLOv5 comparisons.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages