# programmer-rd-ai/detectx architecture

> Architecture diagram of the GitHub repository programmer-rd-ai/detectx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/programmer-rd-ai/detectx
- Repository: https://github.com/programmer-rd-ai/detectx

## Overview

##### Project Type & Purpose
- This is a specialized machine learning framework focused on object detection.
- It’s built on top of Detectron2 and leverages a simple data pipeline, preconfigured models, and built-in evaluation metrics.
- The solution is designed for ease of training and deployment of models along with integrated CI/CD workflows.

##### Main Components
a. ML Core Modules (located under the ML/ directory):
- Dataset Handling (ML/Model/dataset): Represents data ingestion, preprocessing, augmentation, and conversion of input data into formats (e.g., COCO-style annotations) that the training modules can consume.
- Model Implementations (ML/Model/modelling): Encapsulates all the core model logic using Detectron2—this includes setting up models (e.g., Faster R-CNN, RetinaNet), parameter tuning, and interfacing with CUDA for GPU acceleration.
- Evaluation Metrics (ML/Model/metrics): Contains the logic for computing evaluation metrics such as COCO AP, RMSE, MSE, and PSNR to assess model performance.

b. Training & Experimentation Module:
- Main training script (ML/run.py) ties together the dataset, model configuration, and training loop, handling iteration over the data and model optimization steps.
- Parameter tuning utilities (e.g., in ML/Model/param_tunning.py) to adjust hyperparameters based on experiments.

c. Testing & Validation:
- Unit tests and integration tests (both under ML/tests and additional tests directories) verify data pipelines, modelling, and evaluation.
- Extra sample experiments under the tests/ folder (for grid-search, YOLO, TFLite, etc.) show experimentation and comparison among different frameworks or model configurations.

d. CI/CD Pipelines:
- The .github/workflows directory contains multiple YAML files that define CI/CD flows. These workflows likely run tests, lint checks, package builds, and deployments targeted for multiple platforms (Azure, AWS, Google, etc.).
- As supporting components that ensure continuous integration and automated testing.

e. External Dependencies & Integration:
- The framework leverages external libraries like Detectron2, PyTorch, CUDA (for GPU acceleration), and potentially TFLite (as found in tests/tflite).
- As external services/components that interact with the core training modules.

##### Relationships & Data Flow
- The processed data then flows into the Model Implementation module where a specific Detectron2-based configuration (e.g., Faster R-CNN or RetinaNet) is applied for training.
- The trained model’s outcomes are then sent to the Evaluation Metrics module where models are validated and compared in terms of performance using COCO metrics and other error metrics.
- The Training & Experimentation scripts tie these components together, orchestrating model configuration, training, and testing.
- Meanwhile, CI/CD pipelines support the continuous integration by automating tests, builds, and deployment checks.
- External frameworks (Detectron2, PyTorch, CUDA, TFLite) are noted as dependencies that interface with core modules.

##### Architectural Patterns & Design Principles
- Modular Design: Each core functionality (dataset, modelling, evaluation) is separated into its own module/directory (as seen under ML/Model/), which fosters reusability and easy extensibility.
- Separation of Concerns: Data handling, model training, and evaluation are clearly delineated, promoting easier maintenance and debugging.
- CI/CD Integration: Multiple pipeline definitions ensure that each change is automatically validated across different environments.
- Experimentation & Versioning: Multiple versions (as seen in .other/V1 and .other/V2) suggest that the framework may support iterative model enhancement and model registry/versioning for experiments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    A("External Data Source"):::external

    %% External Dependencies
    subgraph "External Dependencies"
        J("Detectron2"):::external
        K("PyTorch"):::external
        L("CUDA (GPU)"):::external
        M("TFLite"):::external
    end

    %% Core ML Modules
    subgraph "ML Core Modules"
        B("Dataset Handling"):::core
        C("Model Implementations"):::core
        D("Detectron2 Configurations"):::core
        E("Evaluation Metrics"):::core
    end

    %% Training & Experimentation
    subgraph "Training & Experimentation"
        F("Main Training Script"):::training
        G("Parameter Tuning Utilities"):::training
    end

    %% Support & Integration
    subgraph "Support & Integration"
        H("Testing & Validation"):::testing
        I("CI/CD Pipelines"):::cicd
    end

    %% Data Flow & Interactions
    A -->|"raw_data"| B
    B -->|"preprocessed_data"| C
    C -->|"utilizes"| D
    C -->|"produces_model"| E
    F -->|"orchestrates"| B
    F -->|"triggers_training"| C
    F -->|"collects_results"| E
    F -->|"invokes"| G
    G -->|"adjusts_params"| F
    E -->|"feedback"| F

    %% CI/CD and Testing Integration
    I ---|"workflow_runs"| F
    I ---|"workflow_runs"| H
    H -->|"validates"| F

    %% External Dependencies Connections
    J -->|"library_dependency"| C
    K -->|"framework_dependency"| C
    L -->|"accelerates"| C
    M -->|"optional_usage"| F

    %% Click Events
    click B "https://github.com/programmer-rd-ai/detectx/tree/main/ML/Model/dataset"
    click C "https://github.com/programmer-rd-ai/detectx/tree/main/ML/Model/modelling"
    click D "https://github.com/programmer-rd-ai/detectx/blob/main/ML/Model/modelling/detectron2.py"
    click E "https://github.com/programmer-rd-ai/detectx/blob/main/ML/Model/metrics.py"
    click F "https://github.com/programmer-rd-ai/detectx/blob/main/ML/run.py"
    click G "https://github.com/programmer-rd-ai/detectx/blob/main/ML/Model/param_tunning.py"
    click H "https://github.com/programmer-rd-ai/detectx/tree/main/ML/tests"
    click I "https://github.com/programmer-rd-ai/detectx/tree/main/.github/workflows"

    %% Style Definitions
    classDef core fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef training fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef testing fill:#D2B4DE,stroke:#7D3C98,stroke-width:2px;
    classDef cicd fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef external fill:#C8E6C9,stroke:#27AE60,stroke-width:2px;
```
