# dbetm/handwritten-flowchart-with-cnn architecture

> Architecture diagram of the GitHub repository dbetm/handwritten-flowchart-with-cnn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dbetm/handwritten-flowchart-with-cnn
- Repository: https://github.com/dbetm/handwritten-flowchart-with-cnn

## Overview

##### File Structure Analysis
- Top-level orchestration:
- handler.py – CLI interface
- preprocessor.py, segmenter.py, splitter.py – pipeline stages to clean, split and segment the input image
- code_generator.py – translates the intermediate representation into C code
- flowchart_generator/ – module that uses Graphviz to build `.dot` files and render flowchart images
- Model directories:
- text_model – text detection: `data/` for generator/preprocessing, `network/` for CNN+LSTM model, `output/` for checkpoints and logs
- Results and assets:
- results/ – holds generated C code, compiled object files, and flowchart outputs
- Images/ and graph_images/ – sample inputs and intermediate visuals
- Config and dependencies:
- requirements.txt / requirements-dev.txt
- model/args.json and various `fix_input_weights_path.py` scripts for path corrections

##### Key README Insights
- Use of continual learning to refine the text model per user
- Final outputs: C source code, compiled binaries, digital flowchart image

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Modules
    Handler["CLI Entry: handler.py"]:::preprocessing
    click Handler "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/handler.py"

    subgraph "Preprocessing Pipeline"
        direction TB
        Preprocessor["Denoise & Binarize: preprocessor.py"]:::preprocessing
        click Preprocessor "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/preprocessor.py"
        Segmenter["Region Identification: segmenter.py"]:::preprocessing
        click Segmenter "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/segmenter.py"
        Splitter["Split Shapes vs Text: splitter.py"]:::preprocessing
        click Splitter "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/splitter.py"
    end

    subgraph "Detection Layer"
        direction TB
        subgraph "Shape-Connector Detector (Faster R-CNN)" 
            direction TB
            ShapeROI["ROI Pooling & Conv: ROI_pooling_conv.py"]:::mlmodel
            click ShapeROI "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/frcnn/ROI_pooling_conv.py"
            ShapeCNN["Backbone CNN: cnn.py"]:::mlmodel
            click ShapeCNN "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/frcnn/cnn.py"
            ShapeAug["Data Augmentation: data_augment.py"]:::mlmodel
            click ShapeAug "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/frcnn/data_augment.py"
            ShapeGen["Data Generator: data_generator.py"]:::mlmodel
            click ShapeGen "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/frcnn/data_generator.py"
            ShapeLoss["Losses: losses.py"]:::mlmodel
            click ShapeLoss "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/frcnn/losses.py"
            ShapeHelpers["ROI Helpers: roi_helpers.py"]:::mlmodel
            click ShapeHelpers "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/frcnn/roi_helpers.py"
            ShapeUtils["Utilities"]:::mlmodel
            click ShapeUtils "https://github.com/dbetm/handwritten-flowchart-with-cnn/tree/master/model/frcnn/utilities/"
        end

        subgraph "Text Detector (Keras-OCR + CNN+LSTM)"
            direction TB
            TextGen["Generator: data/generator.py"]:::mlmodel
            click TextGen "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/text_model/data/generator.py"
            TextPre["Preprocessing: data/preproc.py"]:::mlmodel
            click TextPre "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/text_model/data/preproc.py"
            TextReader["Reader: data/reader.py"]:::mlmodel
            click TextReader "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/text_model/data/reader.py"
            TextModel["CNN+LSTM Model: network/model.py"]:::mlmodel
            click TextModel "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/text_model/network/model.py"
            TextLayers["Custom Layers: network/layers.py"]:::mlmodel
            click TextLayers "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/text_model/network/layers.py"
            TextCheck["Checkpoints & Logs: output/iam/puigcerver/"]:::external
            click TextCheck "https://github.com/dbetm/handwritten-flowchart-with-cnn/tree/master/text_model/output/iam/puigcerver/"
        end

        ExternalModel["External Model Storage"]:::external
    end

    Integration["Interpretation & Integration"]:::preprocessing
    click Integration "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/graph.py"
    click Integration "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/node.py"
    click Integration "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/model/report.py"

    CodeGen["Code Generation: code_generator.py"]:::code
    click CodeGen "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/code_generator.py"

    Compilation["Compilation (gcc)"]:::code

    FlowGen["Flowchart Reconstruction"]:::code
    click FlowGen "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/flowchart_generator/flowchart_generator.py"
    click FlowGen "https://github.com/dbetm/handwritten-flowchart-with-cnn/blob/master/flowchart_generator/assets/flowchart_simbols_and_shape_graphviz.txt"

    Output["Output Store: results/"]:::external
    click Output "https://github.com/dbetm/handwritten-flowchart-with-cnn/tree/master/results/"

    %% Flow
    Handler --> Preprocessor
    Preprocessor --> Segmenter
    Segmenter --> Splitter
    Splitter --> ShapeROI
    Splitter --> TextGen

    ShapeROI --> Integration
    ShapeCNN --> Integration
    ShapeAug --> Integration
    ShapeGen --> Integration
    ShapeLoss --> Integration
    ShapeHelpers --> Integration
    ShapeUtils --> Integration

    TextGen --> Integration
    TextPre --> Integration
    TextReader --> Integration
    TextModel --> Integration
    TextLayers --> Integration
    TextCheck --> Integration

    ExternalModel --> ShapeROI
    ExternalModel --> TextGen

    Integration --> CodeGen
    CodeGen --> Compilation
    Compilation --> FlowGen
    FlowGen --> Output

    %% Feedback for continual learning
    TextGen -->|feedback| TextModel

    %% Styles
    classDef preprocessing fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef mlmodel fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef code fill:#ffa500,stroke:#333,stroke-width:1px;
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:1px;
```
