# sahiliot/biscuit_detection_model architecture

> Architecture diagram of the GitHub repository sahiliot/biscuit_detection_model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sahiliot/biscuit_detection_model
- Repository: https://github.com/sahiliot/biscuit_detection_model

## Overview

This repository is a computer-vision development pipeline for conveyor biscuits: video or Hikvision input is prepared and labeled, YOLO models are trained and evaluated, then deployment or counting scripts detect, track, count, and sometimes measure products. The README documents these stages and future PLC integration; sampled code confirms frame extraction, assisted labeling, training, camera/video inference, and line-crossing measurement. Counting scripts are largely standalone variants, not a shared chained pipeline. Some README-described capabilities have no sampled implementation, so their relationships are documented but unverified.

Main entry points: [`model_training/outputs/diagnostic_results`](https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/outputs/diagnostic_results) (Diagnostic results), [`model_training/data/biscuit_dataset/data.yaml`](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data/biscuit_dataset/data.yaml) (YOLO dataset), [`model_training/data_prep/semi_auto_label.py`](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/semi_auto_label.py) (Assisted labeling), [`model_training/data_prep/generate_data.py`](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/generate_data.py) (Frame extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_extract["Frame extraction<br/>[generate_data.py]"]
  node_empty_data["Empty-frame dataset"]
  node_label["Assisted labeling<br/>[semi_auto_label.py]"]
  node_dataset[("YOLO dataset<br/>[data.yaml]")]
end

subgraph group_model["Model lifecycle"]
  node_train["Initial training<br/>[train_model.py]"]
  node_finetune["Fine-tuning<br/>[fine_tuning.py]"]
  node_model_weights[("Model weights")]
  node_evaluation["Model evaluation"]
end

subgraph group_runtime["Inference and counting"]
  node_video_runtime["Video monitoring<br/>[video_detection.py]"]
  node_cctv_runtime["CCTV inference<br/>[cctv_check.py]"]
  node_count_horizontal["Horizontal counting<br/>[horizontal.py]"]
  node_count_vertical["Vertical counting<br/>[vertical.py]"]
  node_count_detail["Tracked counting<br/>[detailing.py]"]
  node_count_size["Size measurement<br/>[size_measure.py]"]
  node_count_other["Counting variants"]
  node_outputs[("Diagnostic results")]
end

subgraph group_shared["Shared configuration"]
  node_config["Paths and settings<br/>[config.py]"]
end

node_operator(("Engineer"))
node_input_video(("Conveyor video"))
node_hikvision(("Hikvision camera"))
node_plc(("Future PLC"))

node_operator -.->|"selects source"| node_extract
node_input_video -->|"provides frames"| node_extract
node_extract -.->|"creates frames"| node_label
node_operator -.->|"prepares samples"| node_empty_data
node_empty_data -->|"adds empty labels"| node_dataset
node_operator -->|"reviews boxes"| node_label
node_model_weights -->|"proposes boxes"| node_label
node_label -->|"writes annotations"| node_dataset
node_dataset -->|"supplies data"| node_train
node_dataset -->|"supplies data"| node_finetune
node_train -->|"trains weights"| node_model_weights
node_finetune -->|"updates weights"| node_model_weights
node_model_weights -.->|"evaluated by"| node_evaluation
node_model_weights -.->|"loads model"| node_video_runtime
node_model_weights -->|"loads model"| node_cctv_runtime
node_hikvision -->|"streams video"| node_cctv_runtime
node_input_video -.->|"provides video"| node_video_runtime
node_video_runtime -.->|"reports status"| node_outputs
node_cctv_runtime -->|"renders status"| node_outputs
node_input_video -.->|"provides video"| node_count_horizontal
node_input_video -.->|"provides video"| node_count_vertical
node_input_video -.->|"provides video"| node_count_detail
node_input_video -.->|"provides video"| node_count_size
node_count_horizontal -.->|"writes count results"| node_outputs
node_count_vertical -.->|"writes count results"| node_outputs
node_count_detail -.->|"writes count results"| node_outputs
node_count_size -.->|"writes measurements"| node_outputs
node_operator -.->|"reviews metrics"| node_evaluation
node_outputs -.->|"informs integration"| node_plc

click node_config "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/config.py"
click node_extract "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/generate_data.py"
click node_empty_data "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/empty_conveyor_data.py"
click node_label "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/semi_auto_label.py"
click node_dataset "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data/biscuit_dataset/data.yaml"
click node_train "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/training/train_model.py"
click node_finetune "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/training/fine_tuning.py"
click node_evaluation "https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/evaluation"
click node_video_runtime "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/deployment/video_detection.py"
click node_cctv_runtime "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/deployment/cctv_check.py"
click node_count_horizontal "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/horizontal.py"
click node_count_vertical "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/vertical.py"
click node_count_detail "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/detailing.py"
click node_count_size "https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/size_measure.py"
click node_count_other "https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/counting"
click node_outputs "https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/outputs/diagnostic_results"

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_extract,node_empty_data,node_label,node_dataset toneBlue
class node_train,node_finetune,node_model_weights,node_evaluation toneAmber
class node_video_runtime,node_cctv_runtime,node_count_horizontal,node_count_vertical,node_count_detail,node_count_size,node_count_other,node_outputs toneMint
class node_config toneRose
class node_operator,node_input_video,node_hikvision,node_plc toneIndigo
```

## Components

### Data preparation

- [Frame extraction](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/generate_data.py): `model_training/data_prep/generate_data.py`
- [Empty-frame dataset](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/empty_conveyor_data.py): `model_training/data_prep/empty_conveyor_data.py`
- [Assisted labeling](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data_prep/semi_auto_label.py): `model_training/data_prep/semi_auto_label.py`
- [YOLO dataset](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/data/biscuit_dataset/data.yaml): `model_training/data/biscuit_dataset/data.yaml`

### Model lifecycle

- [Initial training](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/training/train_model.py): `model_training/training/train_model.py`
- [Fine-tuning](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/training/fine_tuning.py): `model_training/training/fine_tuning.py`
- **Model weights**
- [Model evaluation](https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/evaluation): `model_training/evaluation`

### Inference and counting

- [Video monitoring](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/deployment/video_detection.py): `model_training/deployment/video_detection.py`
- [CCTV inference](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/deployment/cctv_check.py): `model_training/deployment/cctv_check.py`
- [Horizontal counting](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/horizontal.py): `model_training/counting/horizontal.py`
- [Vertical counting](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/vertical.py): `model_training/counting/vertical.py`
- [Tracked counting](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/detailing.py): `model_training/counting/detailing.py`
- [Size measurement](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/counting/size_measure.py): `model_training/counting/size_measure.py`
- [Counting variants](https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/counting): `model_training/counting`
- [Diagnostic results](https://github.com/sahiliot/biscuit_detection_model/tree/main/model_training/outputs/diagnostic_results): `model_training/outputs/diagnostic_results`

### Shared configuration

- [Paths and settings](https://github.com/sahiliot/biscuit_detection_model/blob/main/model_training/config.py): `model_training/config.py`

### Other components

- **Engineer**
- **Conveyor video**
- **Hikvision camera**
- **Future PLC**

## Connections

- Engineer → Frame extraction: selects source (evidence: `README.md`)
- Conveyor video → Frame extraction: provides frames (evidence: `model_training/data_prep/generate_data.py`)
- Frame extraction → Assisted labeling: creates frames
- Engineer → Empty-frame dataset: prepares samples (evidence: `README.md`)
- Empty-frame dataset → YOLO dataset: adds empty labels (evidence: `model_training/data_prep/empty_conveyor_data.py`)
- Engineer → Assisted labeling: reviews boxes (evidence: `model_training/data_prep/semi_auto_label.py`)
- Model weights → Assisted labeling: proposes boxes (evidence: `model_training/data_prep/semi_auto_label.py`)
- Assisted labeling → YOLO dataset: writes annotations (evidence: `model_training/data_prep/semi_auto_label.py`)
- YOLO dataset → Initial training: supplies data (evidence: `model_training/training/train_model.py`)
- YOLO dataset → Fine-tuning: supplies data (evidence: `model_training/training/fine_tuning.py`)
- Initial training → Model weights: trains weights (evidence: `model_training/training/train_model.py`)
- Fine-tuning → Model weights: updates weights (evidence: `model_training/training/fine_tuning.py`)
- Model weights → Model evaluation: evaluated by (evidence: `README.md`)
- Model weights → Video monitoring: loads model (evidence: `README.md`)
- Model weights → CCTV inference: loads model (evidence: `model_training/deployment/cctv_check.py`)
- Hikvision camera → CCTV inference: streams video (evidence: `model_training/deployment/cctv_check.py`)
- Conveyor video → Video monitoring: provides video (evidence: `README.md`)
- Video monitoring → Diagnostic results: reports status (evidence: `README.md`)
- CCTV inference → Diagnostic results: renders status (evidence: `model_training/deployment/cctv_check.py`)
- Conveyor video → Horizontal counting: provides video (evidence: `README.md`)
- Conveyor video → Vertical counting: provides video (evidence: `README.md`)
- Conveyor video → Tracked counting: provides video (evidence: `README.md`)
- Conveyor video → Size measurement: provides video (evidence: `README.md`)
- Horizontal counting → Diagnostic results: writes count results (evidence: `README.md`)
- Vertical counting → Diagnostic results: writes count results (evidence: `README.md`)
- Tracked counting → Diagnostic results: writes count results (evidence: `README.md`)
- Size measurement → Diagnostic results: writes measurements (evidence: `README.md`)
- Engineer → Model evaluation: reviews metrics (evidence: `README.md`)
- Diagnostic results → Future PLC: informs integration (evidence: `README.md`)
