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.
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:
-
Complete Dataset (~30GB): Download Full SKU-110K Dataset
- Training: 8,233 images
- Validation: 588 images
- Test: 2,941 images
-
Small Dataset (~4GB): Download Small SKU-110K Dataset
- Training: 1,000 images
- Validation: 200 images
- Test: 100 images
- Perfect for quick experimentation and development
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 50This will create a new directory datasets/SKU-110K-Small with the reduced dataset.
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
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 filex1, y1: Top-left corner coordinatesx2, y2: Bottom-right corner coordinatesclass: Always 1 (single class detection)image_width, image_height: Original image dimensions
For quick testing without downloading the full dataset:
- A small sample dataset is included in the repository under
datasets/sample_test/ - Contains 10 test images with annotations
- Useful for testing the inference pipeline
- Download the zip file from the OneDrive link above
- 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- Verify the installation:
python restart/test/test_dataset.pyThis will run basic checks to ensure the dataset is properly organized and readable.
- Clone the repository:
git clone https://github.com/KirbysGit/I2DLproj.git
cd retail-detection- 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- Install dependencies:
pip install -r requirements.txt- 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
- Start training:
python restart/train/trainer.pyTraining outputs will be saved to training_runs/TR_{timestamp}/:
- Model checkpoints in
checkpoints/ - Training visualizations in
visualizations/ - Loss plots and metrics in root directory
- Configure evaluation parameters:
# Edit testing configuration
vim restart/config/testing_config.yaml- Run evaluation:
python restart/test.pyEvaluation outputs will be saved to test_runs/eval_{model}_{timestamp}/:
- Detection visualizations
- Precision-recall curves
- IoU histograms
- Detailed metrics summary