# dmmaze/comic-text-detector architecture

> Architecture diagram of the GitHub repository dmmaze/comic-text-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dmmaze/comic-text-detector
- Repository: https://github.com/dmmaze/comic-text-detector

## Overview

##### Project type and purpose
- This is an open‐source machine‐learning training and inference toolkit for text‐detection and segmentation in manga/comics.
- It provides data generation/preprocessing, dataset interfaces, model definitions (DBNet, UNet, YOLOv5), training scripts (for DBNet, segmentation, YOLO-based block detection), and an inference pipeline.

##### File structure
- Top‐level scripts:
- train_db.py, train_seg.py, train_db_hyp.yaml, train_hyp.yaml, training_hyp.yaml
- train_db.py—DBNet training; train_seg.py—text‐segmentation training; inference.py—inference pipeline
- examples.ipynb—end‐to‐end tutorial
- Data directories:
- data/doc—sample inputs & outputs
- data/examples/fonts, data/examples—resources for synthetic rendering
- data/*.yaml—training hyperparameter configs
- Model definitions:
- basemodel.py—abstract model wrapper
- models/yolov5/*—YOLOv5 block detector integration
- Dataset interfaces:
- db_dataset.py—DBNet dataset loader
- seg_dataset.py—segmentation dataset loader
- Utility modules (utils/):
- db_utils, imgproc_utils, text_rendering, loss, export, general, io_utils, textblock, textmask, weight_init, yolov5_utils

##### Extract insights from the README
- Uses pre‐trained text detector from manga-image-translator
- Generates weak‐supervision labels (text‐lines, masks) via external DL tools
- Has three major pipelines:
a. Synthetic data generation (text_rendering + mask generation)
b. Text‐block detection training (YOLOv5)
c. Text segmentation & line‐detection training (DBNet / UNet approach)
- Inference stitches these to detect bboxes, lines, pixel‐masks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Sources & Storage"
        DS1[(Raw Manga/Comic Images)]:::data
        DS2[(Font Assets)]:::data
        DS3[(Generated Annotations & Synthetic Images)]:::data
    end

    subgraph "Preprocessing & Data Generation"
        TR["text_rendering.py"]:::process
        TM["utils/textmask.py"]:::process
        TB["utils/textblock.py"]:::process
        IP["utils/imgproc_utils.py"]:::process
    end

    subgraph "Dataset Loaders"
        DBDS["db_dataset.py"]:::process
        SGDS["seg_dataset.py"]:::process
    end

    subgraph "Model Components"
        BM["basemodel.py"]:::model
        YO_COMMON["models/yolov5/common.py"]:::model
        YOLO["models/yolov5/yolo.py"]:::model
        YO_UTIL["utils/yolov5_utils.py"]:::model
    end

    subgraph "Training Pipelines"
        T_DB["train_db.py"]:::train
        T_SEG["train_seg.py"]:::train
        HYP1[(train_db_hyp.yaml)]:::train
        HYP2[(train_hyp.yaml)]:::train
        HYP3[(training_hyp.yaml)]:::train
    end

    subgraph "Inference & Export"
        INF["inference.py"]:::inf
        EXP["utils/export.py"]:::inf
        OUT[(Detection Results)]:::inf
    end

    subgraph "Utilities"
        U1["utils/db_utils.py"]:::util
        U2["utils/general.py"]:::util
        U3["utils/io_utils.py"]:::util
        U4["utils/loss.py"]:::util
        U5["utils/weight_init.py"]:::util
        U6["utils/textmask.py"]:::util
        U7["utils/textblock.py"]:::util
        U8["utils/imgproc_utils.py"]:::util
        U9["utils/yolov5_utils.py"]:::util
    end

    DS1 -->|"jpg/png"| TR
    DS2 --> TR
    TR --> DS3
    DS1 --> DS3
    DS3 --> DBDS
    DS3 --> SGDS

    DBDS --> T_DB
    BM --> T_DB
    HYP1 --> T_DB

    SGDS --> T_SEG
    BM --> T_SEG
    HYP2 --> T_SEG

    T_DB --> INF
    T_SEG --> INF

    INF --> EXP
    EXP --> OUT

    %% Utilities connections
    U1 -.-> TR
    U2 -.-> TR
    U3 -.-> DBDS
    U4 -.-> T_DB
    U5 -.-> T_SEG
    U6 -.-> TM
    U7 -.-> TB
    U8 -.-> IP
    U9 -.-> YO_UTIL

    %% Click Events
    click DS1 "https://github.com/dmmaze/comic-text-detector/tree/master/data/doc"
    click DS2 "https://github.com/dmmaze/comic-text-detector/blob/master/data/examples/fonts/msgothic.ttc"
    click TR "https://github.com/dmmaze/comic-text-detector/blob/master/text_rendering.py"
    click TM "https://github.com/dmmaze/comic-text-detector/blob/master/utils/textmask.py"
    click TB "https://github.com/dmmaze/comic-text-detector/blob/master/utils/textblock.py"
    click IP "https://github.com/dmmaze/comic-text-detector/blob/master/utils/imgproc_utils.py"
    click DBDS "https://github.com/dmmaze/comic-text-detector/blob/master/db_dataset.py"
    click SGDS "https://github.com/dmmaze/comic-text-detector/blob/master/seg_dataset.py"
    click BM "https://github.com/dmmaze/comic-text-detector/blob/master/basemodel.py"
    click YO_COMMON "https://github.com/dmmaze/comic-text-detector/blob/master/models/yolov5/common.py"
    click YOLO "https://github.com/dmmaze/comic-text-detector/blob/master/models/yolov5/yolo.py"
    click YO_UTIL "https://github.com/dmmaze/comic-text-detector/blob/master/utils/yolov5_utils.py"
    click T_DB "https://github.com/dmmaze/comic-text-detector/blob/master/train_db.py"
    click T_SEG "https://github.com/dmmaze/comic-text-detector/blob/master/train_seg.py"
    click HYP1 "https://github.com/dmmaze/comic-text-detector/blob/master/data/train_db_hyp.yaml"
    click HYP2 "https://github.com/dmmaze/comic-text-detector/blob/master/data/train_hyp.yaml"
    click HYP3 "https://github.com/dmmaze/comic-text-detector/blob/master/data/training_hyp.yaml"
    click INF "https://github.com/dmmaze/comic-text-detector/blob/master/inference.py"
    click EXP "https://github.com/dmmaze/comic-text-detector/blob/master/utils/export.py"
    click U1 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/db_utils.py"
    click U2 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/general.py"
    click U3 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/io_utils.py"
    click U4 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/loss.py"
    click U5 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/weight_init.py"
    click U6 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/textmask.py"
    click U7 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/textblock.py"
    click U8 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/imgproc_utils.py"
    click U9 "https://github.com/dmmaze/comic-text-detector/blob/master/utils/yolov5_utils.py"

    classDef data fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef process fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef model fill:#FFE0B2,stroke:#E65100,color:#E65100
    classDef train fill:#E1BEE7,stroke:#4A148C,color:#4A148C
    classDef inf fill:#FFCDD2,stroke:#B71C1C,color:#B71C1C
    classDef util fill:#EEEEEE,stroke:#616161,color:#424242
```
