# ductq1801/road-damage-detection-tflite architecture

> Architecture diagram of the GitHub repository ductq1801/road-damage-detection-tflite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ductq1801/road-damage-detection-tflite
- Repository: https://github.com/ductq1801/road-damage-detection-tflite

## Overview

##### Main Components
a. Data & Weights:
- Input Data (raw images, COCO, VOC datasets).
- Pre-trained weights (Darknet weights such as yolov4.weights or yolov4-tiny.weights).
b. Model Conversion & Training Pipeline:
- Conversion modules (save_model.py, convert_tflite.py, convert_trt.py) that transform Darknet models to TensorFlow, TFLite, or TensorRT.
- Training engine (train.py) that supports model training or transfer learning using the provided configuration (core/config.py) and dataset modules (core/dataset.py).
c. Core Detection and Utility Engine:
- Core modules (in the core folder – backbone.py, common.py, config.py, dataset.py, utils.py, and yolov4.py) that define model architectures, data processing, and inference utilities.
- Evaluation scripts (evaluate.py and mAP folder scripts) for performance assessment.
d. Scripts and Data Pipeline:
- Data preparation and conversion tools (scripts folder, including coco_annotation.py, coco_convert.py, and VOC-related scripts) that preprocess datasets.
- Utility scripts for annotations and dataset formatting.
e. Mobile Deployment:
- Android project folder that includes app source code, resource files, and Gradle build scripts.
- Mobile integration using TFLite models (the assets folder holds TFLite models and label/config files).
- Test cases (androidTest folder) to ensure detection functionality.

##### Relationships & Interactions
- Flow from model data input (e.g., Darknet weights and image/video inputs) to the conversion module (save_model.py) then branching out:
– One path for TensorFlow-based detection (using detect.py and detect_video.py scripts) for standard usage.
– Another path for conversion to TFLite (via convert_tflite.py), which feeds into mobile (Android) applications.
– There is an additional branch for TensorRT conversion (via convert_trt.py) for performance optimization.
- The training pipeline (train.py) connects with core modules and datasets to modify/finetune models.
- Evaluation and benchmarking routines (evaluate.py, mAP scripts) loop back to validate the performance of the conversion or training output.

##### Architectural Patterns & Design Principles
- Modular design: The project is separated into distinct modules – conversion, training, evaluation, dataset handling, and mobile deployment.
- Pipeline flow: Indicate a step-by-step data/model processing pipeline (input weights → conversion → training/evaluation → deployment).
- Reusability and extensibility: Core modules (in the core folder) are intended to be reusable across different conversion flows and use cases.

##### Relevant Technologies & Frameworks
- Python for scripting (model training, conversion, evaluation).
- TensorFlow and TFLite for model inference and mobile compatibility.
- TensorRT as an additional optimization layer for GPU-based inference.
- Android (Java-based components and Gradle build system) for on-device inference.
- External datasets (COCO 2017 and VOC) for training and evaluation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Weights and Preprocessing
    subgraph "Data & Weights and Preprocessing"
        A["Raw Data & Pre-trained Weights"]:::data
        B["COCO Annotation (scripts)"]:::script
        C["COCO Conversion (scripts)"]:::script
        D["VOC Tools (scripts)"]:::script
    end

    %% Model Conversion & Training Pipeline
    subgraph "Model Conversion & Training Pipeline"
        E["Save Model (Conversion)"]:::conversion
        F["Train Model (Training Module)"]:::training
        G["Convert to TFLite"]:::conversion
        H["Convert to TensorRT"]:::conversion
        K["Detection Scripts (TensorFlow)"]:::detection
    end

    %% Core Detection & Evaluation Engine
    subgraph "Core Detection & Evaluation Engine"
        I["Core Engine (YOLOv4 & Utilities)"]:::core
        J["Evaluation Module"]:::evaluation
    end

    %% Mobile Deployment
    subgraph "Mobile Deployment"
        L["Android App"]:::mobile
        M["Mobile Assets (TFLite & Labels)"]:::mobile
    end

    %% Connections: Data & Weights to Preprocessing
    A -->|"feeds"| E
    A -->|"feeds"| F
    A --> B
    A --> C
    A --> D

    %% Connections: Conversion Pipeline
    E -->|"branches"| G
    E -->|"branches"| K

    %% Connections: Training and Core Engine
    F -->|"trains"| I
    I -->|"validates"| J

    %% Connections: Conversion outputs to Evaluation and Mobile
    G -->|"mobile_output"| M
    H -->|"optimized_output"| J
    K -->|"used_for"| J

    %% Mobile App Integration
    M -->|"integrated_via_Gradle"| L

%% Click Events for Component Mapping
click B "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/scripts/coco_annotation.py"
click C "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/scripts/coco_convert.py"
click D "https://github.com/ductq1801/road-damage-detection-tflite/tree/main/scripts/voc"
click E "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/save_model.py"
click G "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/convert_tflite.py"
click H "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/convert_trt.py"
click F "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/train.py"
click I "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/core/backbone.py"
click J "https://github.com/ductq1801/road-damage-detection-tflite/blob/main/evaluate.py"
click L "https://github.com/ductq1801/road-damage-detection-tflite/tree/main/android/app/"
click M "https://github.com/ductq1801/road-damage-detection-tflite/tree/main/android/app/src/main/assets"

%% Styles
classDef data fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
classDef script fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
classDef conversion fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
classDef training fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
classDef core fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
classDef evaluation fill:#FADBD8,stroke:#922B21,stroke-width:2px;
classDef detection fill:#D2B4DE,stroke:#7D3C98,stroke-width:2px;
classDef mobile fill:#ABEBC6,stroke:#239B56,stroke-width:2px;
```
