# rosedwayane/aieeg architecture

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

- Interactive diagram: https://gitdiagram.com/rosedwayane/aieeg
- Repository: https://github.com/rosedwayane/aieeg

## Overview

##### Project type and purpose
- This is a PyTorch-based machine-learning inference pipeline (no web frontend) for automatic EEG artifact removal.
- The README describes IC-U-Net and UNet++ variants, both U-Net-style denoising autoencoders for cleaning EEG signals stored as CSV.

##### File structure
- Top level:
- main.py – orchestration script for loading data, selecting model, running inference, and saving output.
- utils.py – data I/O, preprocessing/postprocessing helpers.
- requirements.txt – Python dependencies (numpy, scipy, torch, torchvision, torchaudio).
- sampledata/ – input CSV (30×timepoints) and placeholder output CSV.
- model/ – contains model definitions and checkpoints:
– ICUNet/ (architecture code + modelsave folder with .pth.tar checkpoints and train/val logs)
– UNetpp/ (similar structure)
– UNet_attention.py, UNet_family.py, cumbersome_model2.py – additional model variants.
- image/ – documentation asset (channel_location.JPG).

##### README for additional insights
- It confirms an end-to-end inference flow: set parameters in main.py (input path/name, sample rate, modelname, output path/name), then run `python main.py`.
- No explicit training script in repo (checkpoints are pre-trained and stored under model/*/modelsave).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Stores
    subgraph "Data Stores" 
        direction TB
        inputCSV["Input CSV\n(sampledata/sampledata.csv)"]:::datastore
        outputCSV["Output CSV\n(sampledata/outputsample.csv)"]:::datastore
        ICCheckpoint["IC-U-Net Checkpoints\n(model/ICUNet/modelsave/*.pth.tar)"]:::datastore
        UNetppCheckpoint["UNet++ Checkpoints\n(model/UNetpp/modelsave/*.pth.tar)"]:::datastore
    end

    %% Orchestration
    mainLayer["Orchestration Layer\nmain.py"]:::compute

    %% Preprocessing
    preproc["Preprocessing Module\nutils.py\n(CSV read → NumPy array\n→ normalize → sliding-window)"]:::compute

    %% Model Inference
    subgraph "Model Inference Module" 
        direction TB
        ICUNetArch["IC-U-Net Architecture\n(model/ICUNet/)"]:::model
        UNetppArch["UNet++ Architecture\n(model/UNetpp/)"]:::model
        UNetAttention["UNet_attention.py"]:::model
        UNetFamily["UNet_family.py"]:::model
        Cumbersome["cumbersome_model2.py"]:::model
    end

    %% Postprocessing
    postproc["Postprocessing Module\nutils.py\n(reassemble → scale → CSV data)"]:::compute

    %% Environment & Docs
    env["Environment & Dependencies\nrequirements.txt"]:::env
    readme["README.md"]:::docs
    channelLoc["channel_location.JPG\n(image/)"]:::docs

    %% Data Flow
    inputCSV -->|"raw CSV → NumPy array"| preproc
    preproc -->|"array → tensor"| modelEntry
    mainLayer --> preproc
    mainLayer --> modelEntry
    mainLayer --> postproc

    %% Model entry point as invisible node
    modelEntry([ ]):::none
    modelEntry --> ICUNetArch
    modelEntry --> UNetppArch
    modelEntry --> UNetAttention
    modelEntry --> UNetFamily
    modelEntry --> Cumbersome

    ICCheckpoint -->|"load weights"| ICUNetArch
    UNetppCheckpoint -->|"load weights"| UNetppArch

    ICUNetArch -->|"tensor → cleaned tensor"| postproc
    UNetppArch -->|"tensor → cleaned tensor"| postproc
    UNetAttention -->|"tensor → cleaned tensor"| postproc
    UNetFamily -->|"tensor → cleaned tensor"| postproc
    Cumbersome -->|"tensor → cleaned tensor"| postproc

    postproc -->|"cleaned CSV data"| outputCSV

    %% Orchestration to DataStores
    mainLayer --> inputCSV
    mainLayer --> ICCheckpoint
    mainLayer --> UNetppCheckpoint
    mainLayer --> outputCSV

    %% External Docs
    mainLayer --> readme
    readme --> channelLoc
    mainLayer --> env

    %% Click Events
    click inputCSV "https://github.com/rosedwayane/aieeg/blob/main/sampledata/sampledata.csv"
    click outputCSV "https://github.com/rosedwayane/aieeg/blob/main/sampledata/outputsample.csv"
    click ICCheckpoint "https://github.com/rosedwayane/aieeg/tree/main/model/ICUNet/modelsave"
    click UNetppCheckpoint "https://github.com/rosedwayane/aieeg/tree/main/model/UNetpp/modelsave"
    click mainLayer "https://github.com/rosedwayane/aieeg/blob/main/main.py"
    click preproc "https://github.com/rosedwayane/aieeg/blob/main/utils.py"
    click postproc "https://github.com/rosedwayane/aieeg/blob/main/utils.py"
    click ICUNetArch "https://github.com/rosedwayane/aieeg/tree/main/model/ICUNet/"
    click UNetppArch "https://github.com/rosedwayane/aieeg/tree/main/model/UNetpp/"
    click UNetAttention "https://github.com/rosedwayane/aieeg/blob/main/model/UNet_attention.py"
    click UNetFamily "https://github.com/rosedwayane/aieeg/blob/main/model/UNet_family.py"
    click Cumbersome "https://github.com/rosedwayane/aieeg/blob/main/model/cumbersome_model2.py"
    click env "https://github.com/rosedwayane/aieeg/blob/main/requirements.txt"
    click readme "https://github.com/rosedwayane/aieeg/blob/main/README.md"
    click channelLoc "https://github.com/rosedwayane/aieeg/blob/main/image/channel_location.JPG"

    %% Styles
    classDef datastore fill:#e1f5fe,stroke:#0288d1,stroke-width:2px
    classDef compute fill:#fff9c4,stroke:#fbc02d,stroke-width:2px
    classDef model fill:#c8e6c9,stroke:#388e3c,stroke-width:2px
    classDef env fill:#ffccbc,stroke:#e64a19,stroke-width:2px
    classDef docs fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px
    classDef none fill:none,stroke:none
```
