# ugolomoio/dcae-sr architecture

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

- Interactive diagram: https://gitdiagram.com/ugolomoio/dcae-sr
- Repository: https://github.com/ugolomoio/dcae-sr

## Overview

##### Main components
- Data Input & Preparation:
– Data directories (data, pt_data) and notebooks like prepare_data.ipynb indicate that raw ECG tensors and ancillary information are loaded, preprocessed, and split into train/test datasets.
- Denoising Convolutional Autoencoder (DCAE):
– The core functionality is in designing and using the DCAE for denoising and super resolution. The architecture likely involves an encoder that compresses the noisy ECG signal into a latent space and a decoder that reconstructs the signal at a higher resolution.
- Pretrained Models:
– The models/ directory hints at pretrained network weights available for immediate use. This component should be depicted as a separate module that can be loaded into the autoencoder for restoration tasks.
- Experimental Notebooks & Analysis:
– Multiple notebooks (e.g., ECG-AESR_SingleMode_SignalNoisy.ipynb, ECG-AESR_explainability.ipynb, PlotLatentSpace.ipynb, visual_comparison.ipynb) demonstrate different experimental setups: signal denoising in various modes, robustness tests (e.g., ECG_AESR_robustness_channelmissing.ipynb), and latent space exploration. These illustrate experimental flows and evaluation metrics.
- Classification Pipeline:
– The classification directory (with files like ECGNet.py and classifier.ipynb) sets up an additional branch where a classifier is used (likely based on features from the autoencoder or from the raw ECG data) to distinguish cardiac conditions.

##### Out the relationships and data flows
– Split it into two sub-components: the encoder (feature extraction, compression into latent space) and the decoder (signal reconstruction, super resolution).
– Connect the processed data flow into the encoder and then the decoder, highlighting the latent space in between.
- Introduce a module for “Pretrained Model Loading” that feeds into the autoencoder block, indicating an option for inference and reproduction of experimental results.
- Finally, include a branching “Classification” component where:
– The raw or processed features are sent to an ECG classification model (as represented by the files in the classification directory). This may be depicted as an auxiliary process alongside the reconstruction pipeline.

##### Architectural patterns and design principles
- A modular design separating data ingestion, model training/inference, and evaluation.
- The autoencoder uses a deep learning architecture – highlighting its convolutional layers the denoising mechanism, and the use of a latent space to enable super resolution.
- The existence of pretrained models indicates an emphasis on transfer learning and reproducibility.
- The multiple notebooks show how experimentation is decoupled – where different research aspects (robustness, explainability, p-values analysis) are handled in individual notebooks.

##### Relevant technologies/frameworks
- Python (notebooks and scripts).
- Deep learning frameworks (implicitly, likely PyTorch or TensorFlow; for example, note the *.pt files showing PyTorch model weights).
- Libraries for visualization (matplotlib, etc., as suggested by notebooks like PlotLatentSpace.ipynb).
- Git for version control and reproducibility.

##### Final recommendations
- Be detailed: include intermediary steps where appropriate – for instance, note if data is split, normalized, and how the latent space is formed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion & Preprocessing
    subgraph "Data Ingestion & Preprocessing"
        D1("data/"):::data
        D2("pt_data/"):::data
        D3("prepare_data.ipynb"):::data
        D4(".ipynb_checkpoints/prepare_data-checkpoint.ipynb"):::data
        D5(".virtual_documents/prepare_data.ipynb"):::data
    end

    %% Denoising Convolutional Autoencoder (DCAE)
    subgraph "Denoising Convolutional Autoencoder (DCAE)"
        ENC("Encoder"):::model
        EXP("DCAE Experiments"):::model
        D_A("ptbxl_sr.ipynb"):::model
        D_B("SuperResolutionBaseline.ipynb"):::model
        D_C("functions.py"):::model
        LAT("Latent Space"):::model
        DEC("Decoder"):::model
    end

    %% Pretrained Models Loader
    subgraph "Pretrained Models Loader"
        PM("Pretrained Weights"):::model
    end

    %% Experimental Analysis & Visualization
    subgraph "Experimental Analysis & Visualization"
        E1("ECG-AESR_SingleMode_SignalNoisy.ipynb"):::analysis
        E2("ECG-AESR_SingleMode_SignalNoisyAll.ipynb"):::analysis
        E3("ECG-AESR_SingleMode_SignalNoisy_NoDenoising.ipynb"):::analysis
        E4("ECG-AESR_explainability.ipynb"):::analysis
        E5("ECG_AESR_robustness_channelmissing.ipynb"):::analysis
        E6("PlotLatentSpace.ipynb"):::analysis
        E7("visual_comparison.ipynb"):::analysis
        E8("explain_ablations.ipynb"):::analysis
        E9("inference_time.ipynb"):::analysis
        E10("p_values.ipynb"):::analysis
    end

    %% Classification Module
    subgraph "Classification Module"
        C_DIR("classification/"):::classification
        C1("ECGNet.py"):::classification
        C2("classifier.ipynb"):::classification
    end

    %% Data Ingestion Flow
    D1 --> D3
    D2 --> D3
    D3 --> ENC

    %% DCAE Internal Flow
    D_A --> EXP
    D_B --> EXP
    D_C --> EXP
    EXP --> LAT
    ENC --> LAT
    LAT --> DEC

    %% Pretrained Model Loader connection
    PM ---|"dashed"| ENC

    %% Flow from Autoencoder Output to Experimental Analysis
    DEC --> E1
    DEC --> E4
    DEC --> E7

    %% Flow from Autoencoder Output to Classification Module
    DEC --> C_DIR

    %% Optional Internal Links in Experimental Analysis
    E2 --> E3
    E8 --> E9

    %% Styles
    classDef data fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef model fill:#aed6f1,stroke:#1b4f72,stroke-width:2px;
    classDef analysis fill:#d5f5e3,stroke:#1e8449,stroke-width:2px;
    classDef classification fill:#f9c5d1,stroke:#b03a2e,stroke-width:2px;

    %% Click Events
    click D1 "https://github.com/ugolomoio/dcae-sr/tree/main/data/"
    click D2 "https://github.com/ugolomoio/dcae-sr/tree/main/pt_data/"
    click D3 "https://github.com/ugolomoio/dcae-sr/blob/main/prepare_data.ipynb"
    click D4 "https://github.com/ugolomoio/dcae-sr/blob/main/.ipynb_checkpoints/prepare_data-checkpoint.ipynb"
    click D5 "https://github.com/ugolomoio/dcae-sr/blob/main/.virtual_documents/prepare_data.ipynb"
    click D_A "https://github.com/ugolomoio/dcae-sr/blob/main/ptbxl_sr.ipynb"
    click D_B "https://github.com/ugolomoio/dcae-sr/blob/main/SuperResolutionBaseline.ipynb"
    click D_C "https://github.com/ugolomoio/dcae-sr/blob/main/functions.py"
    click PM "https://github.com/ugolomoio/dcae-sr/tree/main/models/"
    click E1 "https://github.com/ugolomoio/dcae-sr/blob/main/ECG-AESR_SingleMode_SignalNoisy.ipynb"
    click E2 "https://github.com/ugolomoio/dcae-sr/blob/main/ECG-AESR_SingleMode_SignalNoisyAll.ipynb"
    click E3 "https://github.com/ugolomoio/dcae-sr/blob/main/ECG-AESR_SingleMode_SignalNoisy_NoDenoising.ipynb"
    click E4 "https://github.com/ugolomoio/dcae-sr/blob/main/ECG-AESR_explainability.ipynb"
    click E5 "https://github.com/ugolomoio/dcae-sr/blob/main/ECG_AESR_robustness_channelmissing.ipynb"
    click E6 "https://github.com/ugolomoio/dcae-sr/blob/main/PlotLatentSpace.ipynb"
    click E7 "https://github.com/ugolomoio/dcae-sr/blob/main/visual_comparison.ipynb"
    click E8 "https://github.com/ugolomoio/dcae-sr/blob/main/explain_ablations.ipynb"
    click E9 "https://github.com/ugolomoio/dcae-sr/blob/main/inference_time.ipynb"
    click E10 "https://github.com/ugolomoio/dcae-sr/blob/main/p_values.ipynb"
    click C_DIR "https://github.com/ugolomoio/dcae-sr/tree/main/classification/"
    click C1 "https://github.com/ugolomoio/dcae-sr/blob/main/classification/ECGNet.py"
    click C2 "https://github.com/ugolomoio/dcae-sr/blob/main/classification/classifier.ipynb"
```
