# hungcao0402/paddleocr-vietnamese architecture

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

- Interactive diagram: https://gitdiagram.com/hungcao0402/paddleocr-vietnamese
- Repository: https://github.com/hungcao0402/paddleocr-vietnamese

## Overview

##### Overall Project Type and Purpose
- This is a machine learning–based OCR system with multiple components that handle text detection, text recognition, and integrated end-to-end prediction.
- It supports training, evaluating, and exporting models and includes utilities for both model inference (via Docker and dedicated scripts) and preprocessing (labeling and data augmentation).

##### Main Components
a. Core OCR Pipeline (in “ppocr”):
- Detection Models: Contains training configurations (e.g. SAST) and losses, backbones, heads, and metrics related to text detection.
- Recognition Models: Located alongside detection modules and includes SRN-based architectures with losses, backbones, and necks.
b. Data Preprocessing and Augmentation:
- ppocr/data and related augmentation modules (imaug directory with various image augmentation scripts) support the creation and transformation of input datasets.
c. Integrated Inference and Utilities:
- Tools (tools/…) scripts for training, evaluation, model export, and running inference – including the combined detection and recognition pipeline (predict_system.py).
- Dockerfile and run.sh scripts for containerizing and running the complete system.
d. Labeling and Additional Functionality:
- PPOCRLabel: A GUI-based utility for labeling images and managing label dialogs, likely used for data annotation.
- StyleText: A module that appears to handle text stylistic transformations (possibly generating synthetic datasets or stylized text images) with its own architecture and configuration.
e. Document/Table Structure Analysis:
- ppstructure: Contains submodules for layout and table extraction, expanding the scope to document structure analysis.
f. Configuration and Deployment:
- Configs: Includes YAML configuration files for both the detection and recognition models.
- Setup and deployment scripts (setup.py, requirements.txt, Dockerfile) which support reproducibility and containerized deployment.

##### Relationships and Interactions
- Data flows from raw images (potentially annotated using PPOCRLabel) through a preprocessing/augmentation stage (found in ppocr/data/imaug) to training components.
- The training pipelines (tools/train.py and configurations in configs/) feed into model building in both the detection and recognition branches.
- Post-training, evaluation is performed (tools/eval.py) and the trained models are exported (tools/export_model.py) for inference.
- The integrated inference pipeline (tools/infer/predict_system.py) ties both detection and recognition together to provide end-to-end OCR.
- Ancillary modules (StyleText and ppstructure) augment the core OCR tasks with stylization or document layout analysis.

##### Important Architectural Patterns and Technologies
- Modular design is apparent: separate directories for detection, recognition, pre- and post-processing, and model architectures.
- Clear separation between training, inference, evaluation, and deployment – with each functionality isolated in its own script or module.
- Use of configuration files to drive experiments and model parameters, which also means the system is highly configurable.
- Deployment via Docker emphasizes reproducible and containerized environments.
- Utilizes PaddlePaddle (as indicated in the setup instructions) for deep learning implementations.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Subgraph: Data Input & Preprocessing
  subgraph "Data Input & Preprocessing"
    A1["PPOCRLabel (Annotation)"]:::auxiliary
    A2["Data & Augmentation (imaug)"]:::preprocessing
  end

  %% Subgraph: Training Modules
  subgraph "Training Modules"
    subgraph "Detection Training"
      D1["Detection Config (SAST)"]:::training
      D2["SAST Head"]:::training
      D3["SAST Loss"]:::training
    end
    subgraph "Recognition Training"
      R1["Recognition Config (SRN)"]:::training
      R2["SRN Head"]:::training
      R3["SRN Loss"]:::training
    end
  end

  %% Subgraph: Training Utilities
  subgraph "Training Utilities"
    T1["Train Utility (tools/train.py)"]:::training
    T2["Evaluation Utility (tools/eval.py)"]:::training
    T3["Export Utility (tools/export_model.py)"]:::training
  end

  %% Subgraph: Inference & Deployment
  subgraph "Inference & Deployment"
    I1["Unified Inference Pipeline (tools/infer/predict_system.py)"]:::inference
    subgraph "Deployment Scripts"
      DS1["Run Script (run.sh)"]:::inference
      DS2["Dockerfile"]:::inference
      DS3["Setup Script (setup.py)"]:::inference
    end
  end

  %% Subgraph: Auxiliary Modules
  subgraph "Auxiliary Modules"
    Amp1["StyleText (Text Stylizer)"]:::auxiliary
    Amp2["ppstructure (Document Analysis)"]:::auxiliary
  end

  %% Connections
  A1 --> A2
  A2 -->|"feeds"| D1
  A2 -->|"feeds"| R1

  D1 --> D2
  D2 --> D3
  R1 --> R2
  R2 --> R3

  D3 -->|"combined output"| T1
  R3 --> T1

  T1 --> T2
  T2 --> T3
  T3 --> I1
  I1 --> DS1
  I1 --> DS2
  DS2 --> DS3

  %% Auxiliary integration
  A1 --- Amp1
  Amp1 --- T1
  Amp2 --- I1

  %% Click Events
  click D1 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/configs/det/SAST.yml"
  click D2 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/ppocr/modeling/heads/det_sast_head.py"
  click D3 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/ppocr/losses/det_sast_loss.py"
  click R1 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/configs/rec/SRN.yml"
  click R2 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/ppocr/modeling/heads/rec_srn_head.py"
  click R3 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/ppocr/losses/rec_srn_loss.py"
  click A2 "https://github.com/hungcao0402/paddleocr-vietnamese/tree/master1/ppocr/data/imaug"
  click I1 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/tools/infer/predict_system.py"
  click T1 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/tools/train.py"
  click T2 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/tools/eval.py"
  click T3 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/tools/export_model.py"
  click DS1 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/run.sh"
  click DS2 "https://github.com/hungcao0402/paddleocr-vietnamese/tree/master1/Dockerfile"
  click DS3 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/setup.py"
  click A1 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/PPOCRLabel/PPOCRLabel.py"
  click Amp1 "https://github.com/hungcao0402/paddleocr-vietnamese/tree/master1/StyleText/arch"
  click Amp2 "https://github.com/hungcao0402/paddleocr-vietnamese/blob/master1/ppstructure/predict_system.py"

  %% Styles
  classDef preprocessing fill:#FFB6C1,stroke:#000,stroke-width:2px;
  classDef training fill:#ADD8E6,stroke:#000,stroke-width:2px;
  classDef inference fill:#90EE90,stroke:#000,stroke-width:2px;
  classDef auxiliary fill:#FFD700,stroke:#000,stroke-width:2px;
```
