# open-mmlab/mmocr architecture

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

- Interactive diagram: https://gitdiagram.com/open-mmlab/mmocr
- Repository: https://github.com/open-mmlab/mmocr

## Overview

##### Main Components
- Core Framework Modules: Include the essential libraries (mmocr, mmengine, mmcv, mmdetection) that provide the backbone for training and inference.
- Data Handling Pipeline:
- Datasets: Represented by folders like mmocr/datasets, dataset_zoo, and the numerous dataset preparers, parsers, dumpers, gatherers, and samplers.
- Data Converters: The tools/dataset_converters ensure external data can be brought in or transformed.
- Model Components:
- Models: The mmocr/models directory is sub-modularized by task (textdet, textrecog, kie) with further breakdown into backbones, necks, heads, pre-processors, decoders, and losses.
- Configurations: The various configs and project-specific configurations (in projects/*) that define model architectures, training schedules, datasets, etc.
- Inference and Evaluation:
- Inferencers/API: The mmocr/apis/inferencers highlight real-time prediction components and evaluation functions.
- Evaluator & Metrics: Separate modules in mmocr/evaluation to calculate hmean, IoU, and other metrics.
- Engine:
- Training and Inference Engine: The mmocr/engine directory deals with training pipelines, hooks (e.g., visualization hook), and custom runtime routines.
- Utilities:
- Essential utilities from mmocr/utils and visualization modules, which include file I/O, transforms, and visualization utilities.
- Supporting scripts and pipelines:
- Tools: Scripts for training (tools/train.py), testing (tools/test.py, tools/infer.py), distributed training (tools/dist_train.sh, tools/dist_test.sh) and model converters.
- CI/CD and documentation: Directories like .circleci, .github, and docs illustrate integration/testing and documentation pipelines, but they might appear as peripheral “infrastructure” components.
- Projects and Community Extensions:
- Projects: Separate sub-projects (e.g., ABCNet, SPTS, example_project) capturing specialized or extended pipelines for text spotting.
- Demo and sample notebooks, which provide usage examples.

##### Architectural Patterns and Design Principles
- Modular design principle – each module (e.g., dataset preparers, parsers, model decoders) is individually developed and replaceable.
- “config-driven” approach: separate configuration files allow the user to easily adjust model parameters, training schedules, and data pipelines.

##### Technologies and Frameworks
- Clearly label use of PyTorch as the core deep learning framework.
- Dependencies on OpenMMLab libraries such as MMEngine, MMCV, and MMDetection.
- Integration with CI/CD tools (CircleCI, GitHub Actions) as part of automated testing and deployment workflows.
- External interfaces (APIs) for inferencing.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data Input & Preprocessing Layer
    subgraph "Data Input & Preprocessing"
         A["External Datasets (dataset_zoo)"]:::data
         B["Internal Datasets (mmocr/datasets)"]:::data
         C["Data Converters (tools/dataset_converters)"]:::data
    end

    %% Model & Core Algorithm Layer
    subgraph "Model & Core Algorithm"
         D["MMOCR Core (mmocr)"]:::core
         E["Model Components (mmocr/models)"]:::core
         F1["Configurations (configs)"]:::config
         F2["Projects (projects/ABCNet, projects/SPTS, projects/example_project)"]:::config
    end

    %% Engine Layer
    subgraph "Engine"
         G["Training/Inference Engine (mmocr/engine)"]:::engine
    end

    %% Inference & Evaluation Layer
    subgraph "Inference & Evaluation"
         H["Inferencers/API (mmocr/apis/inferencers)"]:::inference
         I["Evaluator & Metrics (mmocr/evaluation)"]:::inference
    end

    %% Utilities and Supporting Layer
    subgraph "Utilities and Supporting"
         J1["Utilities (mmocr/utils)"]:::utils
         J2["Visualization (mmocr/visualization)"]:::utils
         K["Supporting Scripts (tools)"]:::infra
         subgraph "CI/CD and Docs"
             L1["CI/CD (.circleci)"]:::infra
             L2["CI/CD (.github)"]:::infra
             L3["Documentation (docs)"]:::infra
         end
    end

    %% Connections for Data Flow
    A -->|"raw_data"| B
    C -->|"convert"| B
    B -->|"feeds"| E
    F1 -->|"configures"| E
    F2 -->|"projects_configure"| E
    D -->|"supports"| E
    D -->|"provides_core"| G
    E -->|"models_run_in"| G
    G -->|"inference"| H
    G -->|"evaluation"| I
    G -->|"utilizes"| J1
    G -->|"visualizes"| J2
    K -->|"orchestrates"| G
    L1 ---|"triggers"| K
    L2 ---|"triggers"| K
    L3 ---|"supports"| K

    %% Click Events
    click A "https://github.com/open-mmlab/mmocr/tree/main/dataset_zoo"
    click B "https://github.com/open-mmlab/mmocr/tree/main/mmocr/datasets"
    click C "https://github.com/open-mmlab/mmocr/tree/main/tools/dataset_converters"
    click D "https://github.com/open-mmlab/mmocr/tree/main/mmocr"
    click E "https://github.com/open-mmlab/mmocr/tree/main/mmocr/models"
    click F1 "https://github.com/open-mmlab/mmocr/tree/main/configs"
    click F2 "https://github.com/open-mmlab/mmocr/tree/main/projects"
    click G "https://github.com/open-mmlab/mmocr/tree/main/mmocr/engine"
    click H "https://github.com/open-mmlab/mmocr/tree/main/mmocr/apis/inferencers"
    click I "https://github.com/open-mmlab/mmocr/tree/main/mmocr/evaluation"
    click J1 "https://github.com/open-mmlab/mmocr/tree/main/mmocr/utils"
    click J2 "https://github.com/open-mmlab/mmocr/tree/main/mmocr/visualization"
    click K "https://github.com/open-mmlab/mmocr/tree/main/tools"
    click L1 "https://github.com/open-mmlab/mmocr/blob/main/.circleci"
    click L2 "https://github.com/open-mmlab/mmocr/blob/main/.github"
    click L3 "https://github.com/open-mmlab/mmocr/tree/main/docs"

    %% Styles
    classDef data fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef core fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef config fill:#a9dfbf,stroke:#1e8449,stroke-width:2px;
    classDef engine fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef inference fill:#f5cba7,stroke:#cd6133,stroke-width:2px;
    classDef utils fill:#fcf3cf,stroke:#f1c40f,stroke-width:2px;
    classDef infra fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
```
