# caitzpp/lrp-code architecture

> Architecture diagram of the GitHub repository caitzpp/lrp-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/caitzpp/lrp-code
- Repository: https://github.com/caitzpp/lrp-code

## Overview

##### Project Type and Purpose
- This repository is an open-source Python toolkit for applying and visualizing Layer-Wise Relevance Propagation (LRP) on convolutional neural networks trained to classify Alzheimer’s disease (AD) from structural MRI data.
- It bundles a general LRP wrapper (innvestigator.py + inverter_util.py), a simple MNIST example, MRI-specific evaluation and plotting notebooks, plus supporting data-handling and model-training modules (nitorch, jrieke).

##### File Structure Analysis
- Top-Level Scripts & Notebooks
- innvestigator.py & inverter_util.py: core LRP wrapper & utilities
- mnist_test.py, multiple .ipynb notebooks (MNIST example, ADNI evaluation, plotting)
- Python Packages
- jrieke/: dataset loaders, interpretation logic, model definitions, helpers
- nitorch/: generic DL pipeline modules (data, transforms, models, trainer, inference, callbacks, metrics, loss, utils)
- Configuration & Resources
- settings.py: user-provided paths to data, models, masks
- binary_brain_mask.nii.gz, nmm_mask_areas.py: MRI mask resources
- docker/: Dockerfile + docker-compose.yml for reproducible CPU-only Jupyter environment
- Support Files
- requirements.txt, license.txt, .gitignore

##### Key README Insights
- Core workflow: load pre-trained PyTorch model → wrap with InnvestigateModel → call .innvestigate(in_tensor) → receive prediction + relevance heatmap
- Visualization notebooks demonstrate end-to-end use on MRI and MNIST data
- Docker + Jupyter provide an isolated dev environment

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data & Configuration"
        DS1["MRI & HDF5 Data"]:::data
        DM1["binary_brain_mask.nii.gz"]:::data
        DM2["nmm_mask_areas.py"]:::data
        CFG["Configuration (settings.py)"]:::data
    end

    subgraph "Data Loader & Preprocessor"
        DL1["jrieke.datasets"]:::compute
        DL2["nitorch.data"]:::compute
        DL3["nitorch.transforms"]:::compute
    end

    subgraph "Model Layer"
        M1["jrieke.models"]:::compute
        M2["nitorch.models"]:::compute
        M3["Saved Models (mymodel/)"]:::compute
    end

    subgraph "Training & Inference Pipeline"
        T1["nitorch.trainer"]:::compute
        T2["nitorch.inference"]:::compute
        T3["nitorch.callbacks"]:::compute
    end

    subgraph "LRP Wrapper (Core Engine)"
        W1["innvestigator.py"]:::compute
        W2["inverter_util.py"]:::compute
    end

    subgraph "Metric Computation & Analysis"
        MC["nmm_mask_areas.py"]:::compute
    end

    subgraph "Visualization & Examples"
        V1["MNIST example.ipynb"]:::viz
        V2["Evaluate GB and LRP.ipynb"]:::viz
        V3["Plotting result graphs.ipynb"]:::viz
        V4["Plotting brain maps.ipynb"]:::viz
        V5["mnist_test.py"]:::viz
    end

    subgraph "Deployment & UI"
        D1["Docker + Jupyter"]:::infra
        D2["docker-compose.yml"]:::infra
    end

    %% Data flow
    DS1 --> DL1
    DM1 --> DL1
    CFG --> DL1
    DL1 --> DL2 --> DL3 --> M1 --> M2 --> M3
    M3 --> T1 --> T2 --> W1 --> W2 --> MC
    MC --> V1
    MC --> V2
    MC --> V3
    MC --> V4
    MC --> V5
    D1 --> V1
    D1 --> V2
    D1 --> V3
    D1 --> V4
    D1 --> V5
    D2 --> D1

    %% Click events
    click DM1 "https://github.com/caitzpp/lrp-code/blob/master/binary_brain_mask.nii.gz"
    click DM2 "https://github.com/caitzpp/lrp-code/blob/master/nmm_mask_areas.py"
    click CFG "https://github.com/caitzpp/lrp-code/blob/master/settings.py"
    click DL1 "https://github.com/caitzpp/lrp-code/blob/master/jrieke/datasets.py"
    click DL2 "https://github.com/caitzpp/lrp-code/blob/master/nitorch/data.py"
    click DL3 "https://github.com/caitzpp/lrp-code/blob/master/nitorch/transforms.py"
    click M1 "https://github.com/caitzpp/lrp-code/blob/master/jrieke/models.py"
    click M2 "https://github.com/caitzpp/lrp-code/blob/master/nitorch/models.py"
    click M3 "https://github.com/caitzpp/lrp-code/tree/master/mymodel/"
    click T1 "https://github.com/caitzpp/lrp-code/blob/master/nitorch/trainer.py"
    click T2 "https://github.com/caitzpp/lrp-code/blob/master/nitorch/inference.py"
    click T3 "https://github.com/caitzpp/lrp-code/blob/master/nitorch/callbacks.py"
    click W1 "https://github.com/caitzpp/lrp-code/blob/master/innvestigator.py"
    click W2 "https://github.com/caitzpp/lrp-code/blob/master/inverter_util.py"
    click MC "https://github.com/caitzpp/lrp-code/blob/master/nmm_mask_areas.py"
    click V1 "https://github.com/caitzpp/lrp-code/blob/master/MNIST example.ipynb"
    click V2 "https://github.com/caitzpp/lrp-code/blob/master/Evaluate GB and LRP.ipynb"
    click V3 "https://github.com/caitzpp/lrp-code/blob/master/Plotting result graphs.ipynb"
    click V4 "https://github.com/caitzpp/lrp-code/blob/master/Plotting brain maps.ipynb"
    click V5 "https://github.com/caitzpp/lrp-code/blob/master/mnist_test.py"
    click D1 "https://github.com/caitzpp/lrp-code/tree/master/docker/Dockerfile"
    click D2 "https://github.com/caitzpp/lrp-code/blob/master/docker/docker-compose.yml"

    %% Styles
    classDef data fill:#D0E6FF,stroke:#005B9A,color:#005B9A;
    classDef compute fill:#DFF0D8,stroke:#3C763D,color:#3C763D;
    classDef viz fill:#FCF8E3,stroke:#8A6D3B,color:#8A6D3B;
    classDef infra fill:#F2F2F2,stroke:#666666,color:#666666;
```
