# chien3553/fruit_detection_yolov7_pyside6 architecture

> Architecture diagram of the GitHub repository chien3553/fruit_detection_yolov7_pyside6, 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/chien3553/fruit_detection_yolov7_pyside6
- Repository: https://github.com/chien3553/fruit_detection_yolov7_pyside6

## Overview

##### Project Type and Purpose
- This is a full-stack application for real‐time object (fruit) detection in images, videos, or webcam feeds.
- It builds on YOLOv7 for the detection model and uses PySide6 for the GUI.
- Additionally, there’s support for external hardware integration (Arduino’s LCD display) and deployment capabilities (e.g., Triton Inference Server).

##### Analyzing the File Structure
- Top-Level Files: Files like main.py, detect.py, train.py, and export.py are key entry points for various functionalities – detection, training, and exporting results.
- UI: The “ui” directory contains main.ui (the PySide6 UI definition) which defines the graphical interface.
- Models & Configurations:
- The “models” directory (with files like yolo.py, common.py, experimental.py) encapsulates the deep learning model’s logic.
- The “cfg” directory houses multiple YAML configuration files that define model architectures for baseline, training, and deployment purposes.
- The “ptmodel”, “pretrain”, and “best.pt” files store model weights.
- Utilities: “utils” hosts helper modules (for dataset handling, loss calculations, plotting, etc.) and includes specialized directories for AWS, Google App Engine, and wandb logging. This suggests that the project has modular utilities to support training and deployment.
- Deployment: The “deploy” directory contains scripts for integrating with external services like Triton Inference Server, while “arduino” (with an LCD subfolder) illustrates hardware integration.
- Additional Scripts: Files like YoloClass.py and MouseLabel.py might augment model operation and interactive labeling, which further clarifies the separation of concerns.

──A. Main Components to Include:
- User Interface (GUI): Represented by “ui/main.ui” and its underlying PySide6 code. This is the presentation layer where users import images, video, or webcam feeds, adjust settings (confidence, IoU), and view real-time feedback.
- Detection Engine: Centered around the YOLO model logic:
- Core modules in “models/” (including models/yolo.py) implement detection.
- Configurations in “cfg/” and model weight files (e.g., in “ptmodel”, “pretrain”).
- Detection orchestration via files like detect.py and main.py.
- Utilities and Helpers: Encapsulate routines for data handling, metrics, and plotting found in the “utils/” directory.
- Hardware/External Integrations:
- Arduino Integration: The “arduino” directory (e.g., LCD/LCD.ino) shows that the system communicates with an Arduino LCD for displaying results.
- Deployment/Inference Server: The “deploy/triton-inference-server” folder indicates additional endpoints for inference serving.
──B. Component Relationships & Data Flow:
- Input Flow: Start with images, video, or webcam streams imported via the GUI.
- Processing Flow: The detection engine (invoked from main.py or detect.py) passes the input data through the YOLO model. This part uses the model definitions (from the “models” folder) and configuration settings (from the “cfg” directory).
- Output Routing: Processed results are sent back to the GUI for display and statistics. There might also be an optional flow that sends detection results to the Arduino-controlled LCD.
- Training/Export Flow: Separate modules (train.py, export.py, train_aux.py) allow for updating models and exporting results.
- Deployment Flow: Optionally, the system can be packaged for inference using Triton Inference Server as indicated by the “deploy/triton-inference-server” scripts.
──C. Architectural Patterns & Design Principles:
- Modularity: Clear separation between UI, detection logic, utility/helper functions, configuration management, and hardware integration.
- Loose Coupling: The GUI communicates with the backend detection engine through defined interfaces, making it easier to swap or upgrade modules independently.
- Extensibility: The directory layout (with clearly separated “cfg”, “models”, “utils”, and “deploy” folders) suggests that adding new models, input types, or deployment strategies is straightforward.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI["User Interface (PySide6)"]:::frontend
    end

    %% Detection Engine (YOLOv7) with internal modules
    subgraph "Detection Engine (YOLOv7)"
        subgraph "Orchestration"
            main["main.py"]:::backend
            detect["detect.py"]:::backend
        end
        subgraph "Model Components"
            model["Model Definitions (models/yolo.py)"]:::backend
            config["Configurations (cfg)"]:::backend
            weights["Model Weights (ptmodel)"]:::backend
        end
    end

    %% Utilities & Helpers
    subgraph "Utilities & Helpers"
        UTIL["Utilities & Helpers (utils)"]:::utility
    end

    %% Hardware Integration Layer
    subgraph "Hardware Integration"
        HW["Arduino LCD (LCD.ino)"]:::hardware
    end

    %% Deployment / Inference Server
    subgraph "Deployment/Inference Server"
        DEPLOY["Deployment/Inference Server (triton)"]:::deploy
    end

    %% Data Flow Connections
    UI -->|"input"| main
    main -->|"calls"| model
    main -->|"calls"| config
    main -->|"calls"| weights
    detect -->|"calls"| model
    detect -->|"calls"| config
    detect -->|"calls"| weights
    main -->|"returns"| UI
    main -->|"utilizes"| UTIL
    main -->|"sends"| HW
    main -->|"deploys"| DEPLOY

    %% Click Events
    click UI "https://github.com/chien3553/fruit_detection_yolov7_pyside6/blob/main/ui/main.ui"
    click main "https://github.com/chien3553/fruit_detection_yolov7_pyside6/blob/main/main.py"
    click detect "https://github.com/chien3553/fruit_detection_yolov7_pyside6/blob/main/detect.py"
    click model "https://github.com/chien3553/fruit_detection_yolov7_pyside6/blob/main/models/yolo.py"
    click config "https://github.com/chien3553/fruit_detection_yolov7_pyside6/tree/main/cfg/"
    click weights "https://github.com/chien3553/fruit_detection_yolov7_pyside6/blob/main/ptmodel/best.pt"
    click UTIL "https://github.com/chien3553/fruit_detection_yolov7_pyside6/tree/main/utils/"
    click HW "https://github.com/chien3553/fruit_detection_yolov7_pyside6/blob/main/arduino/LCD/LCD.ino"
    click DEPLOY "https://github.com/chien3553/fruit_detection_yolov7_pyside6/tree/main/deploy/triton-inference-server/"

    %% Class Definitions for colors
    classDef frontend fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2e86c1,stroke-width:2px;
    classDef utility fill:#a3e4d7,stroke:#1abc9c,stroke-width:2px;
    classDef hardware fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef deploy fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
```
