# alejandrodopico2/cifnet architecture

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

- Interactive diagram: https://gitdiagram.com/alejandrodopico2/cifnet
- Repository: https://github.com/alejandrodopico2/cifnet

## Overview

- Configuration Module: Represented by the “cfgs” directory that contains all YAML configuration files for different datasets (e.g., CIFAR10_random.yaml, MNIST_random.yaml). This module provides hyperparameters, dataset paths, and training options.

- Model Architecture Module: The “models” directory contains the core network implementations (e.g., CIFNet.py) and supportive modules such as “ROLANN.py”, “backbone.py”, as well as samplers (in models/samplers, e.g., MemoryExpansionBuffer.py and SamplingStrategy.py). This module is the heart of how incremental learning is achieved.

- Utility & Visualization Module: The “utils” directory features helper functions for loading data (load_cifar.py), model utilities (model_utils.py), plotting, and visualizing results, which are vital for debugging and analyzing training performance.

- Execution & Training Pipeline: The main execution scripts are “main.py” and “train_cifnet.py”. These scripts act as entry points that integrate configurations, data loaders, models, and utilities to perform training and experimentation.

##### Relationships/Interactions

- Startup Phase:
- The system begins in the top-level execution scripts (main.py/train_cifnet.py) that read a configuration file from the “cfgs” folder.

- Data Flow:
- The execution scripts invoke the “Data Loading & Preprocessing Module” to load and prepare data according to the specified configuration.

- Model Training:
- The trained model components are constructed from the “Model Architecture Module”. Data streams into the model from the loaders.
- Additionally, the samplers (e.g., MemoryExpansionBuffer) within the models interact to manage the compressed buffer mechanism that minimizes memory usage.

- Evaluation & Visualization:
- After training, utilities under the “Utility Module” (such as plotting and result visualization) process and produce training curves and performance metrics.

- External Dependencies:
- Use of external libraries such as PyTorch (with torchvision for dataset downloads), Python 3.9, and other dependencies from requirements.txt.
- Separate labeled external modules representing “PyTorch/torchvision” interacting with data loaders and model training.

##### Incorporate Architectural Patterns & Design Principles

- Layered design: configuration leads to data ingestion, then model training, and finally visualization and evaluation.
- Single-step training innovation and the compressed buffer mechanism in the “Model Architecture Module” to mitigate catastrophic forgetting—these should be annotated near relevant modules like “models/CIFNet.py” and samplers.
- Stress modularity: each directory (configuration, data loading, models, utilities) is an independent module, clearly isolated by its functionality.

##### Putting It All Together

▸ Configuration (cfgs) – provides parameters.
▸ Data Loader (incremental_dataloaders) – fetches and prepares data.
▸ Model (models folder) – houses CIFNet, backbone, and samplers.
▸ Utility (utils) – for model evaluation and results visualization.

- Wherever applicable, annotate that the design supports real-time training on resource-constrained devices, emphasizing the design goals of efficiency and low-energy consumption.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Execution & Training Pipeline
    subgraph "Execution & Training Pipeline"
        EP1["main.py"]:::exec
        EP2["train_cifnet.py"]:::exec
    end

    %% Configuration Module
    CFG["Configuration Module"]:::config

    %% Data Loading & Preprocessing Module
    subgraph "Data Loading & Preprocessing Module"
        DLD["Data Loader (incremental_dataloaders)"]:::loader
        ds1["custom_datasets.py"]:::loader
        ds2["data_preparation.py"]:::loader
        ds3["datasets.py"]:::loader
    end

    %% Model Architecture Module
    subgraph "Model Architecture Module"
        MOD["Model (models)"]:::model
        cifnet["CIFNet.py"]:::model
        rolann["ROLANN.py"]:::model
        backbone["backbone.py"]:::model
        subgraph "Samplers"
            memBuff["MemoryExpansionBuffer.py"]:::model
            samplingStrat["SamplingStrategy.py"]:::model
        end
    end

    %% Utility & Visualization Module
    subgraph "Utility & Visualization Module"
        UTIL["Utility (utils)"]:::util
        l_cifar["load_cifar.py"]:::util
        modelUtils["model_utils.py"]:::util
        plotting["plotting.py"]:::util
        visualize["visualize_results.py"]:::util
    end

    %% External Dependencies
    external["PyTorch/torchvision"]:::external

    %% Connections
    EP1 -->|"reads_config"| CFG
    EP2 -->|"reads_config"| CFG

    CFG -->|"provides_params"| DLD

    EP1 -->|"triggers_loading"| DLD
    EP2 -->|"triggers_loading"| DLD

    DLD -->|"loads_custom_dataset"| ds1
    DLD -->|"executes_preparation"| ds2
    DLD -->|"handles_datasets"| ds3

    DLD -->|"supplies_batches"| MOD

    EP1 -->|"initiates_training"| MOD
    EP2 -->|"initiates_training"| MOD

    MOD -->|"runs_CIFNet"| cifnet
    MOD -->|"includes_ROLANN"| rolann
    MOD -->|"integrates_backbone"| backbone
    MOD -->|"utilizes_sampler"| memBuff
    MOD -->|"utilizes_sampler"| samplingStrat

    MOD -->|"outputs_predictions"| UTIL

    EP1 -->|"triggers_visualization"| UTIL
    EP2 -->|"triggers_visualization"| UTIL

    external -->|"downloads_data"| DLD
    external -->|"supports_compute"| MOD

    %% Click Events
    click CFG "https://github.com/alejandrodopico2/cifnet/tree/main/cfgs/"
    click DLD "https://github.com/alejandrodopico2/cifnet/tree/main/incremental_dataloaders/"
    click ds1 "https://github.com/alejandrodopico2/cifnet/blob/main/incremental_dataloaders/custom_datasets.py"
    click ds2 "https://github.com/alejandrodopico2/cifnet/blob/main/incremental_dataloaders/data_preparation.py"
    click ds3 "https://github.com/alejandrodopico2/cifnet/blob/main/incremental_dataloaders/datasets.py"
    click MOD "https://github.com/alejandrodopico2/cifnet/tree/main/models/"
    click cifnet "https://github.com/alejandrodopico2/cifnet/blob/main/models/CIFNet.py"
    click rolann "https://github.com/alejandrodopico2/cifnet/blob/main/models/ROLANN.py"
    click backbone "https://github.com/alejandrodopico2/cifnet/blob/main/models/backbone.py"
    click memBuff "https://github.com/alejandrodopico2/cifnet/blob/main/models/samplers/MemoryExpansionBuffer.py"
    click samplingStrat "https://github.com/alejandrodopico2/cifnet/blob/main/models/samplers/SamplingStrategy.py"
    click UTIL "https://github.com/alejandrodopico2/cifnet/tree/main/utils/"
    click l_cifar "https://github.com/alejandrodopico2/cifnet/blob/main/utils/load_cifar.py"
    click modelUtils "https://github.com/alejandrodopico2/cifnet/blob/main/utils/model_utils.py"
    click plotting "https://github.com/alejandrodopico2/cifnet/blob/main/utils/plotting.py"
    click visualize "https://github.com/alejandrodopico2/cifnet/blob/main/utils/visualize_results.py"
    click EP1 "https://github.com/alejandrodopico2/cifnet/blob/main/main.py"
    click EP2 "https://github.com/alejandrodopico2/cifnet/blob/main/train_cifnet.py"

    %% Styles
    classDef exec fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef config fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef loader fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef model fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef util fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef external fill:#87CEFA,stroke:#333,stroke-width:2px;
```
