# xuwangyin/at-ebms architecture

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

- Interactive diagram: https://gitdiagram.com/xuwangyin/at-ebms
- Repository: https://github.com/xuwangyin/at-ebms

## Overview

- Data Preparation and Management:
- “prepare_datasets” directory (with shell scripts like create_celebahq256.sh and create_afhqcat256.sh) and associated download/extraction utilities. Also note that the datasets (e.g., CelebA-HQ, AFHQ, LSUN, CIFAR-10, tiny images) are external inputs managed via instructions in the README.
- Utility Modules:
- “GOOD/tiny_utils” folder (with various text files, configuration scripts like tiny_path_config.py, and data utilities for tiny images). This module provides helper routines and possibly configuration management for handling the 80M tiny images dataset.
- Model Definitions:
- Use the “models” folder (e.g., robustness_resnet_cifar10.py) and note that it is where the network architectures are defined.
- Training Engine:
- Adversarial Attack Modules:
- Components like “attack_steps.py” and “pgd_attack.py”. These modules implement adversarial aspects (for both generation and worst-case OOD detection) that are essential to the learning process.
- Evaluation and Generation:
- Experiment Management:
- Mention external directories (checkpoints, data, experiments) that need to be placed at the project root for reproducing results, as mentioned in the README.
- Additional Scripts and Modules:
- “dataset.py”, “misc.py”, “eval_utils.py”, and possibly components like “auto-attack” or “InNOutRobustness” (which might be additional modules for robustness evaluation or automatic attack generation).

- Data Preparation → Training Engine:
- Utility/Configuration → All Modules:
- Have the utility modules (tucked under GOOD/tiny_utils) feed configuration, support, or data handling functions to both training and evaluation stages.
- Model Definitions → Training Engine:
- The “models” module should be shown as a dependency of the training module. The training script instantiates these models according to the configurations and datasets.
- Adversarial Attacks → Training Engine and Evaluation:
- Generation and Evaluation:
- External Data Dependencies:

##### Architectural Patterns and Design Principles
- Modular Structure:
- That the project is modular by nature: Data preparation, training, model definition, adversarial module, and evaluation are kept largely separated to promote clarity and extensibility.
- Script-Driven Pipeline:
- Plug-and-Play Evaluation:
- That additional experiments (such as FID evaluation and 2D experiments via notebooks) are “plugged” into the core pipeline, marked as auxiliary evaluation components.
- Utilization of Popular Frameworks:
- Use of PyTorch/TorchVision for model training, possibly TensorFlow for FID scoring, and other libraries as mentioned in the README. They can be annotated next to relevant components (e.g., “models” and “train.py” rely on PyTorch).

- External datasets, pre-trained checkpoints, and scripts for dataset creation.
- Proceed to a “Processing” Layer:
- Training Engine centrally located, with its subsidiary modules (Models, Adversarial Attacks, Utility components) linked to it.
- End with an “Output/Evaluation” Layer:
- Evaluation modules that analyze generated images (FID), perform OOD detection, or generate experimental outputs.
- Every component and connection is clearly labeled to reflect the instructions in the README and the file tree structure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input Layer
    subgraph "Data Input"
        EXTERNAL_DATA["External Datasets"]:::input
        PRETRAINED["Pre-trained Checkpoints/Experiments"]:::input
    end

    %% Data Preparation Layer
    subgraph "Data Preparation"
        PD["prepare_datasets"]:::module
    end

    %% Core Processing Layer
    subgraph "Core Processing"
        UM["GOOD/tiny_utils"]:::module
        MD["models"]:::module
        AA1["attack_steps.py"]:::module
        AA2["pgd_attack.py"]:::module
        AS1["dataset.py"]:::module
        AS2["misc.py"]:::module
        AS3["eval_utils.py"]:::module
        TM["train.py"]:::module
    end

    %% Evaluation Layer
    subgraph "Evaluation"
        EV1["generate.py"]:::evaluation
        EV2["fid.py"]:::evaluation
        EV3["eval_ood.py"]:::evaluation
        EV4["eval_fid"]:::evaluation
    end

    %% Connections from Data Input
    EXTERNAL_DATA --> PD
    EXTERNAL_DATA --> TM
    PRETRAINED --> TM

    %% Data Preparation to Training Engine
    PD --> TM

    %% Utility and Modules dependencies to Training Engine
    UM --> TM
    MD --> TM
    AA1 --> TM
    AA2 --> TM
    AS1 --> TM
    AS2 --> TM
    AS3 --> TM

    %% Training Engine outputs to Evaluation
    TM --> EV1
    TM --> EV2
    TM --> EV3
    TM --> EV4

    %% Adversarial Modules also support Evaluation (OOD detection)
    AA1 --> EV3
    AA2 --> EV3

    %% Utility support to Evaluation (configuration, data handling)
    UM --> EV1
    UM --> EV2

    %% Styles
    classDef input fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef module fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef evaluation fill:#90EE90,stroke:#000,stroke-width:2px;

    %% Click Events
    click PD "https://github.com/xuwangyin/at-ebms/tree/main/prepare_datasets"
    click UM "https://github.com/xuwangyin/at-ebms/tree/main/GOOD/tiny_utils"
    click MD "https://github.com/xuwangyin/at-ebms/tree/main/models"
    click TM "https://github.com/xuwangyin/at-ebms/blob/main/train.py"
    click AA1 "https://github.com/xuwangyin/at-ebms/blob/main/attack_steps.py"
    click AA2 "https://github.com/xuwangyin/at-ebms/blob/main/pgd_attack.py"
    click AS1 "https://github.com/xuwangyin/at-ebms/blob/main/dataset.py"
    click AS2 "https://github.com/xuwangyin/at-ebms/blob/main/misc.py"
    click AS3 "https://github.com/xuwangyin/at-ebms/blob/main/eval_utils.py"
    click EV1 "https://github.com/xuwangyin/at-ebms/blob/main/generate.py"
    click EV2 "https://github.com/xuwangyin/at-ebms/blob/main/fid.py"
    click EV3 "https://github.com/xuwangyin/at-ebms/blob/main/eval_ood.py"
    click EV4 "https://github.com/xuwangyin/at-ebms/tree/main/eval_fid"
```
