# ekourlit/torch-reweighter architecture

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

- Interactive diagram: https://gitdiagram.com/ekourlit/torch-reweighter
- Repository: https://github.com/ekourlit/torch-reweighter

## Overview

##### Main Components
- Data Input & Preprocessing: Represented by “data.py” (which likely deals with reading and formatting HDF5 3D images) and possibly “variables.py” (for configurations) along with the “conda_environment.yml” for dependency management.
- Model Definition: Encapsulated in “models.py” and the “models” directory that contains pre-trained checkpoints (e.g., conv3d models with various configurations such as batch normalization and GPU setups).
- Training Pipeline: Centered around “train.py” (with “train.submit” as a submission script for job scheduling) that orchestrates the model training process using the defined data and NN architecture.
- Evaluation Module: “evaluate.py” is responsible for assessing network performance possibly using metrics related to the reweighting correction performance.
- Utility & Visualization Tools: “plotUtils.py” provides the plotting/visualization functions, likely used for analyzing training performance or data distributions.
- External Dependencies & Environment: “conda_environment.yml” ensures that the computing environment (such as GPU drivers and deep-learning libraries) is correctly configured.

##### Relationships and Interactions
- Data Flow: Begin with the data ingestion component (data.py) that reads and preprocesses the 3D images. This component feeds processed data to the Training Module (train.py) and, indirectly, to the Evaluation Module (evaluate.py).
- Evaluation and Reweighting: Indicate how evaluation procedures use outputs from the model (trained checkpoints) and the processed data to compute classification scores. These scores are then applied to reweight the degraded observables.
- Visualization & Diagnostics: The plotUtils.py module should be shown connected to both the training and evaluation modules to generate graphs for performance metrics and validation outcomes.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize the clear separation between data handling, model architecture, training procedures, evaluation, and visualization. Each module (data, model, training, evaluation) is a distinct component interacting via well-defined interfaces.
- Separation of Concerns: By isolating processing, model definition, and evaluation into separate scripts, the design facilitates easier debugging, testing, and reuse.
- Code Reusability and Checkpointing: The use of saved model files (in the models directory) highlights the adoption of checkpointing practices that support iterative experimentation.

##### Elements
- Clear Labels: For each component (e.g., “Data Preprocessing – data.py”, “Model Architecture – models.py”, “Training Pipeline – train.py”, “Evaluation Module – evaluate.py”, “Visualization – plotUtils.py”).
- Annotation: Add annotations for key aspects such as “3D Convolution NN”, “HDF5 images”, “GPU Acceleration”, and “Checkpointing” to highlight crucial technical details.
- External Dependencies: Represent the environment setup (specified in conda_environment.yml) by incorporating a separate node denoting “Environment / Dependencies” connecting to the training and inference components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data & Config"
        DInput["Data Preprocessing (data.py)"]:::data
        Config["Configuration (variables.py)"]:::data
    end

    subgraph "Model Definition"
        ModelDef["Model Architecture (models.py)"]:::model
        ModelCheck["Model Checkpoints (models/)"]:::model
    end

    subgraph "Training Pipeline"
        Train["Training Process (train.py)"]:::training
        JobSub["Job Submission (train.submit)"]:::training
    end

    subgraph "Evaluation & Visualization"
        Eval["Evaluation Module (evaluate.py)"]:::evaluation
        Plot["Visualization (plotUtils.py)"]:::evaluation
    end

    subgraph "Environment"
        Env["Environment & Dependencies (conda_environment.yml)"]:::env
    end

    %% Environment feeds into components
    Env -->|"provides"| DInput
    Env -->|"provides"| Train
    Env -->|"provides"| Eval

    %% Data flow from data & config to training and evaluation
    DInput -->|"processed_data"| Train
    Config -->|"parameters"| Train
    DInput -->|"data"| Eval

    %% Training interactions
    Train -->|"scheduling"| JobSub
    Train -->|"instantiates"| ModelDef
    ModelDef -->|"checkpointing"| ModelCheck
    Train -->|"trained_model"| Eval
    ModelCheck -->|"checkpoint_input"| Eval

    %% Visualization connections
    Train -->|"training_plots"| Plot
    Eval -->|"evaluation_plots"| Plot

    %% Class definitions for colors
    classDef data fill:#ffefc7,stroke:#d69d38,stroke-width:2px;
    classDef model fill:#c7ffd8,stroke:#38a832,stroke-width:2px;
    classDef training fill:#c7e3ff,stroke:#387ad6,stroke-width:2px;
    classDef evaluation fill:#e0c7ff,stroke:#8c38d6,stroke-width:2px;
    classDef env fill:#f0f0f0,stroke:#999,stroke-width:2px;

    %% Click Events
    click DInput "https://github.com/ekourlit/torch-reweighter/blob/main/data.py"
    click Config "https://github.com/ekourlit/torch-reweighter/blob/main/variables.py"
    click Env "https://github.com/ekourlit/torch-reweighter/blob/main/conda_environment.yml"
    click ModelDef "https://github.com/ekourlit/torch-reweighter/blob/main/models.py"
    click ModelCheck "https://github.com/ekourlit/torch-reweighter/tree/main/models/"
    click Train "https://github.com/ekourlit/torch-reweighter/blob/main/train.py"
    click JobSub "https://github.com/ekourlit/torch-reweighter/blob/main/train.submit"
    click Eval "https://github.com/ekourlit/torch-reweighter/blob/main/evaluate.py"
    click Plot "https://github.com/ekourlit/torch-reweighter/blob/main/plotUtils.py"
```
