# vmc-7645/yolov8-retail architecture

> Architecture diagram of the GitHub repository vmc-7645/yolov8-retail, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vmc-7645/yolov8-retail
- Repository: https://github.com/vmc-7645/yolov8-retail

## Overview

This repository is a model-development workspace for retail object detection, not a general application. The architecture centers on a YOLOv8 training pipeline, exported model artifacts, and several standalone inference scripts for different input types.

1. **Core purpose**
   The project detects retail products on shelves using YOLOv8. The repo is organized around experimentation: train models, evaluate them, export them, and run them against images, video, or webcam feeds.

2. **Primary subsystems**
   There are three main subsystems:
   - **Training** under `training/`
   - **Testing / inference** under `testing/`
   - **Saved model artifacts** under `model/`
   
   These are separate boundaries: training produces weights and metrics, while testing consumes exported weights to run detection.

3. **Training pipeline**
   `training/train.py`, `training/test.py`, and the helper scripts in `training/` drive YOLOv8 training and evaluation. The README shows training is typically done through the Ultralytics CLI with a `custom.yaml` dataset config and a pretrained base model such as `yolov8n.pt`. This layer depends on PyTorch/CUDA and the YOLOv8 implementation.

4. **Dataset boundary**
   The training data comes from the SKU110k retail dataset, referenced in the README. That dataset is external to the repo and provides labeled shelf images. The repo’s `custom.yaml` is the key interface between the external dataset and the YOLOv8 training process.

5. **Model versioning**
   The `model/` directory is a versioned artifact store. Each version folder, such as `model/0.0.1`, `model/0.1.3`, `model/0.2.1`, and `model/0.2.8`, contains:
   - trained weights (`best.pt`, `last.pt`)
   - exported inference weights (`best.onnx` in some versions)
   - training metadata (`args.yaml`)
   - evaluation outputs (`results.csv`, sometimes `predictions.json`)
   - TensorBoard logs (`events.out.tfevents...`)
   
   This makes the repo’s “deployment boundary” explicit: the training pipeline produces versioned model packages.

6. **Inference / testing layer**
   `testing/` contains the runtime scripts used to apply trained models:
   - `image_object_detection.py`
   - `video_object_detection.py`
   - `webcam_object_detection.py`
   
   These are thin modality-specific entry points over the same detection logic. They load model files from `testing/models/` and produce detections on static images, video files, or live camera streams.

7. **Model format conversion**
   `testing/convertPT.py` and `training/yolov8-convert.py` indicate a conversion step between PyTorch `.pt` weights and ONNX `.onnx` models. That matters architecturally because training is done in PyTorch, but inference can be distributed or reused more easily via ONNX.

8. **Shared YOLOv8 support code**
   `testing/yolov8/YOLOv8.py` and `testing/yolov8/utils.py` are local support modules that likely encapsulate model loading, preprocessing, postprocessing, and visualization. They form the reusable inference core shared by the image/video/webcam scripts.

9. **Output and labeling flow**
   The testing side also includes `vid-to-labeledvid.py`, which suggests a pipeline to convert raw video into a labeled video with detections overlaid. This indicates the repo supports not only prediction, but also visualization/export of annotated results.

10. **Artifact locations for inference**
   `testing/models/` contains ONNX model files such as `best.onnx` and `best18.onnx`. This directory is the runtime model repository for test scripts, separate from the historical training artifacts in `model/`.

11. **Experiment lifecycle**
   The lifecycle is: train on SKU110k-derived data -> evaluate -> export weights -> store artifacts in a versioned `model/<version>/` folder -> copy a chosen model into `testing/models/` -> run inference scripts. The architecture is therefore a research-to-field workflow rather than a continuous service.

12. **Operational assumptions**
   The repository is optimized for local execution on Windows with CUDA, as stated in the README. The key external dependencies are Ultralytics YOLOv8, PyTorch, and CUDA-enabled GPU support. There is no evidence of a backend server, database, or message bus; the system is file-based and script-driven.

13. **What an architecture diagram should show**
   A useful diagram would include:
   - external dataset source → training config/scripts → YOLOv8 training/evaluation
   - trained model artifacts → versioned model storage
   - exported ONNX / PT weights → inference scripts
   - inference inputs from image/video/webcam → annotated detection outputs
   - optional conversion step between `.pt` and `.onnx`

Overall, this repo is best understood as an end-to-end YOLOv8 experiment and deployment toolkit for retail shelf detection, with versioned model artifacts as the central bridge between training and inference.

Main entry points: [`training/train.py`](https://github.com/vmc-7645/yolov8-retail/blob/main/training/train.py) (Train), [`testing/models`](https://github.com/vmc-7645/yolov8-retail/tree/main/testing/models) (testing/models), [`testing/yolov8/YOLOv8.py`](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/yolov8/YOLOv8.py) (YOLOv8 core), [`model/0.0.1`](https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.0.1) (0.0.1)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Repo"]
  node_external_dataset[("SKU110k<br/>external dataset")]
  node_readme["README<br/>project overview<br/>[README.md]"]
  node_run_script["run.py<br/>launcher<br/>[run.py]"]
end

subgraph group_training["Training"]
  node_train_script["Train<br/>[train.py]"]
  node_eval_script["Test<br/>evaluation script<br/>[test.py]"]
  node_dataset_yaml["custom.yaml<br/>dataset config<br/>[custom.yaml]"]
  node_pretrained_base["yolov8n.pt<br/>base weights<br/>[yolov8n.pt]"]
  node_train_convert["Convert<br/>export script<br/>[yolov8-convert.py]"]
  node_train_cleanup["Clean<br/>utility script<br/>[yolov8-clean.py]"]
end

subgraph group_testing["Testing"]
  node_runtime_models[("testing/models<br/>runtime weights")]
  node_pt_to_onnx["convertPT<br/>conversion script<br/>[convertPT.py]"]
  node_image_infer["Image detect<br/>inference entrypoint"]
  node_video_infer["Video detect<br/>inference entrypoint"]
  node_webcam_infer["Webcam detect<br/>inference entrypoint"]
  node_label_video["Label video<br/>postprocess script"]
  node_yolo_core["YOLOv8 core<br/>shared inference code<br/>[YOLOv8.py]"]
  node_yolo_utils["Utils<br/>shared inference code<br/>[utils.py]"]
end

subgraph group_models["Model Store"]
  node_artifact_v001[("0.0.1<br/>versioned model<br/>[0.0.1]")]
  node_artifact_v013[("0.1.3<br/>versioned model<br/>[0.1.3]")]
  node_artifact_v021[("0.2.1<br/>versioned model<br/>[0.2.1]")]
  node_artifact_v028[("0.2.8<br/>versioned model<br/>[0.2.8]")]
end

node_external_dataset -->|"labels"| node_dataset_yaml
node_dataset_yaml -->|"feeds"| node_train_script
node_pretrained_base -->|"initializes"| node_train_script
node_train_script -->|"validates"| node_eval_script
node_train_script -->|"exports"| node_train_convert
node_train_script -->|"produces"| node_artifact_v001
node_train_script -->|"produces"| node_artifact_v013
node_train_script -->|"produces"| node_artifact_v021
node_train_script -->|"produces"| node_artifact_v028
node_train_convert -->|"writes"| node_artifact_v001
node_artifact_v001 -->|"promotes"| node_runtime_models
node_artifact_v013 -->|"promotes"| node_runtime_models
node_artifact_v021 -->|"promotes"| node_runtime_models
node_artifact_v028 -->|"promotes"| node_runtime_models
node_pt_to_onnx -->|"writes"| node_runtime_models
node_runtime_models -->|"loads"| node_yolo_core
node_yolo_core -->|"uses"| node_yolo_utils
node_yolo_core -->|"shared by"| node_image_infer
node_yolo_core -->|"shared by"| node_video_infer
node_yolo_core -->|"shared by"| node_webcam_infer
node_video_infer -->|"annotates"| node_label_video
node_run_script -.->|"orchestrates"| node_train_script
node_run_script -.->|"orchestrates"| node_image_infer

click node_readme "https://github.com/vmc-7645/yolov8-retail/blob/main/README.md"
click node_run_script "https://github.com/vmc-7645/yolov8-retail/blob/main/run.py"
click node_train_script "https://github.com/vmc-7645/yolov8-retail/blob/main/training/train.py"
click node_eval_script "https://github.com/vmc-7645/yolov8-retail/blob/main/training/test.py"
click node_dataset_yaml "https://github.com/vmc-7645/yolov8-retail/blob/main/training/custom.yaml"
click node_pretrained_base "https://github.com/vmc-7645/yolov8-retail/blob/main/training/yolov8n.pt"
click node_train_convert "https://github.com/vmc-7645/yolov8-retail/blob/main/training/yolov8-convert.py"
click node_train_cleanup "https://github.com/vmc-7645/yolov8-retail/blob/main/training/yolov8-clean.py"
click node_artifact_v001 "https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.0.1"
click node_artifact_v013 "https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.1.3"
click node_artifact_v021 "https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.2.1"
click node_artifact_v028 "https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.2.8"
click node_runtime_models "https://github.com/vmc-7645/yolov8-retail/tree/main/testing/models"
click node_pt_to_onnx "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/convertPT.py"
click node_image_infer "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/image_object_detection.py"
click node_video_infer "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/video_object_detection.py"
click node_webcam_infer "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/webcam_object_detection.py"
click node_label_video "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/vid-to-labeledvid.py"
click node_yolo_core "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/yolov8/YOLOv8.py"
click node_yolo_utils "https://github.com/vmc-7645/yolov8-retail/blob/main/testing/yolov8/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_external_dataset,node_readme,node_run_script toneBlue
class node_train_script,node_eval_script,node_dataset_yaml,node_pretrained_base,node_train_convert,node_train_cleanup toneAmber
class node_runtime_models,node_pt_to_onnx,node_image_infer,node_video_infer,node_webcam_infer,node_label_video,node_yolo_core,node_yolo_utils toneMint
class node_artifact_v001,node_artifact_v013,node_artifact_v021,node_artifact_v028 toneRose
```

## Components

### Repo

Project overview and top-level orchestration.

- **SKU110k**: external dataset · Retail shelf dataset used as the training source.
- [README](https://github.com/vmc-7645/yolov8-retail/blob/main/README.md): project overview · Repository-level description and usage guide. · `README.md`
- [run.py](https://github.com/vmc-7645/yolov8-retail/blob/main/run.py): launcher · Top-level script for running repository workflows. · `run.py`

### Training

YOLOv8 training, evaluation, and export pipeline.

- [Train](https://github.com/vmc-7645/yolov8-retail/blob/main/training/train.py): training entrypoint · Main YOLOv8 training script. · `training/train.py`
- [Test](https://github.com/vmc-7645/yolov8-retail/blob/main/training/test.py): evaluation script · Training-side evaluation or validation script. · `training/test.py`
- [custom.yaml](https://github.com/vmc-7645/yolov8-retail/blob/main/training/custom.yaml): dataset config · Dataset interface between local training and external labels. · `training/custom.yaml`
- [yolov8n.pt](https://github.com/vmc-7645/yolov8-retail/blob/main/training/yolov8n.pt): base weights · Pretrained YOLOv8 starting point for fine-tuning. · `training/yolov8n.pt`
- [Convert](https://github.com/vmc-7645/yolov8-retail/blob/main/training/yolov8-convert.py): export script · Training-side conversion from PyTorch weights to ONNX. · `training/yolov8-convert.py`
- [Clean](https://github.com/vmc-7645/yolov8-retail/blob/main/training/yolov8-clean.py): utility script · Training-side helper for workspace cleanup or maintenance. · `training/yolov8-clean.py`

### Testing

Inference entry points and shared runtime helpers.

- [testing/models](https://github.com/vmc-7645/yolov8-retail/tree/main/testing/models): runtime weights · Inference-time ONNX model repository. · `testing/models`
- [convertPT](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/convertPT.py): conversion script · Standalone conversion from .pt to .onnx for inference use. · `testing/convertPT.py`
- [Image detect](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/image_object_detection.py): inference entrypoint · Runs detection on static images. · `testing/image_object_detection.py`
- [Video detect](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/video_object_detection.py): inference entrypoint · Runs detection on video files. · `testing/video_object_detection.py`
- [Webcam detect](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/webcam_object_detection.py): inference entrypoint · Runs detection on live camera input. · `testing/webcam_object_detection.py`
- [Label video](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/vid-to-labeledvid.py): postprocess script · Creates annotated or labeled video output from detections. · `testing/vid-to-labeledvid.py`
- [YOLOv8 core](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/yolov8/YOLOv8.py): shared inference code · Reusable loader and inference logic shared by test scripts. · `testing/yolov8/YOLOv8.py`
- [Utils](https://github.com/vmc-7645/yolov8-retail/blob/main/testing/yolov8/utils.py): shared inference code · Shared preprocessing, postprocessing, and visualization helpers. · `testing/yolov8/utils.py`

### Model Store

Versioned trained artifacts and runtime model files.

- [0.0.1](https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.0.1): versioned model · Stored training run with weights, metrics, and exports. · `model/0.0.1`
- [0.1.3](https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.1.3): versioned model · Stored training run with weights and metrics. · `model/0.1.3`
- [0.2.1](https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.2.1): versioned model · Stored training run with weights and metrics. · `model/0.2.1`
- [0.2.8](https://github.com/vmc-7645/yolov8-retail/blob/main/model/0.2.8): versioned model · Stored training run with weights, metrics, and predictions. · `model/0.2.8`

## Connections

- SKU110k → custom.yaml: labels · The external retail dataset is referenced through the dataset config.
- custom.yaml → Train: feeds · Training consumes the dataset configuration to locate images and annotations.
- yolov8n.pt → Train: initializes · Training starts from a pretrained YOLOv8 checkpoint.
- Train → Test: validates · Training is paired with evaluation of the trained detector.
- Train → Convert: exports · Training produces exportable model artifacts.
- Train → 0.0.1: produces · A training run is stored as a versioned model package.
- Train → 0.1.3: produces · A training run is stored as a versioned model package.
- Train → 0.2.1: produces · A training run is stored as a versioned model package.
- Train → 0.2.8: produces · A training run is stored as a versioned model package.
- Convert → 0.0.1: writes · Converted exports can be materialized inside versioned artifacts.
- 0.0.1 → testing/models: promotes · Chosen trained weights are copied into the inference model store.
- 0.1.3 → testing/models: promotes · Chosen trained weights are copied into the inference model store.
- 0.2.1 → testing/models: promotes · Chosen trained weights are copied into the inference model store.
- 0.2.8 → testing/models: promotes · Chosen trained weights are copied into the inference model store.
- convertPT → testing/models: writes · Standalone conversion populates ONNX files for inference.
- testing/models → YOLOv8 core: loads · Inference core loads the deployed model weights.
- YOLOv8 core → Utils: uses · Core inference depends on shared helper utilities.
- YOLOv8 core → Image detect: shared by · Image detection script uses the shared YOLOv8 runtime.
- YOLOv8 core → Video detect: shared by · Video detection script uses the shared YOLOv8 runtime.
- YOLOv8 core → Webcam detect: shared by · Webcam detection script uses the shared YOLOv8 runtime.
- Video detect → Label video: annotates · Video inference feeds labeled video generation.
- run.py → Train: orchestrates · Top-level script can invoke training workflows.
- run.py → Image detect: orchestrates · Top-level script can invoke inference workflows.
