# vt-le/astnet architecture

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

- Interactive diagram: https://gitdiagram.com/vt-le/astnet
- Repository: https://github.com/vt-le/astnet

## Overview

##### Main Components
- Data Input / Pre-processing: Represent the module that takes in video datasets (such as UCSD Ped2, CUHK Avenue, and ShanghaiTech Campus), which is managed in the “datasets” folder. Components such as “label_data” and “video_data” support data parsing and preparation.
- Configuration Management: Show that the system uses different YAML and Python configuration files (found in the “config” folder) that tailor model settings to each dataset.
- Model / Autoencoder Architecture: Highlight the “models” directory which contains various implementations (e.g., basic modules, wider_resnet, etc.). Indicate that the core of the system is an attention-based residual autoencoder. If needed, break down this component further into encoder, decoder, residual (or attention) blocks.
- Training and Evaluation Pipelines:
- The “train.py” script handles the training pipeline.
- The “test.py” script handles model evaluation.
- Utility Functions: Show the “utils” module that provides support for logging, loss calculation, optimizer selection, and other training utilities.
- Static & Visualization: Although not the primary computational module, the “static” directory (with CSS, JS, images) supports visualization of results like anomaly curves/graphs.

##### Relationships and Data Flow
- Next, configuration files (YAML files for different datasets) feed settings into both the training and testing scripts.
- The training process (triggered by train.py) loads the dataset via the “datasets” modules, configures and instantiates the autoencoder model (from the “models” modules), and uses utility functions (from “utils”) for things like logging and loss computation.
- Similarly, the test.py script is used for evaluation – it loads the pretrained model, applies it to the test data, and then outputs anomaly detection results that might be visualized using the static assets.
- Data ingestion → preprocessing (datasets module)
- Configurations are passed to the train/test scripts (configuration management)
- Main model component (autoencoder and attention modules) interacts with data and logo/cost functions
- Results (outputs) flow into visual elements in the static folder when needed.

##### Important Architectural Patterns and Design Principles
- Modularization: Clear separation into folders (config, datasets, models, utils) supports a modular design.
- Configuration Driven: The system relies on YAML configuration files to easily switch between different datasets and model variants.
- Pipeline Architecture: The design follows the training pipeline (data → model → training loop) and testing pipeline.
- Extensibility: With separate modules for models and datasets, adding new datasets or altering the architecture can be done in isolated parts of the system.

##### Relevant Technologies and Frameworks
- The project is built using Python and PyTorch (as specified in the README).
- The static assets in CSS/JS hint at some basic web-based visualization (for example, showing anomaly detection curves or supporting a dashboard).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Input Layer
    subgraph "Input Layer"
        vd["Video Datasets"]:::input
        subgraph "Data Management"
            d_dir["ASTNet/datasets"]:::input
            ld["label_data.py"]:::input
            vd_file["video_data.py"]:::input
        end
    end

    %% Configuration Layer
    subgraph "Configuration Management"
        config_dir["ASTNet/config"]:::config
        yaml1["avenue_wresnet.yaml"]:::config
        yaml2["ped2_wresnet.yaml"]:::config
        yaml3["shanghaitech_wresnet.yaml"]:::config
        defaults["defaults.py"]:::config
    end

    %% Model Architecture
    subgraph "Model Architecture (Attention-based Residual Autoencoder)"
        model_dir["ASTNet/models"]:::model
        basic["basic_modules.py"]:::model
        w_resnet["wider_resnet.py"]:::model
        ws1024["wresnet1024_cattn_tsm.py"]:::model
        ws2048["wresnet2048_multiscale_cattn_tsmplus_layer6.py"]:::model
    end

    %% Utility Functions
    subgraph "Utility Functions"
        utils_dir["ASTNet/utils"]:::utils
        anomaly["anomaly_util.py"]:::utils
        log["log_util.py"]:::utils
        loss["loss_util.py"]:::utils
        opt["optimizer_util.py"]:::utils
        train_util["train_util.py"]:::utils
    end

    %% Training Pipeline
    subgraph "Training Pipeline"
        train_py["ASTNet/train.py"]:::pipeline
    end

    %% Evaluation Pipeline
    subgraph "Evaluation Pipeline"
        test_py["ASTNet/test.py"]:::pipeline
    end

    %% Visualization
    subgraph "Visualization / Static Assets"
        static_dir["static"]:::visual
        static_css["static/css"]:::visual
        static_js["static/js"]:::visual
        static_img["static/img"]:::visual
    end

    %% Internal connections within clusters
    d_dir --> ld
    d_dir --> vd_file

    config_dir --> yaml1
    config_dir --> yaml2
    config_dir --> yaml3
    config_dir --> defaults

    model_dir --> basic
    model_dir --> w_resnet
    model_dir --> ws1024
    model_dir --> ws2048

    utils_dir --> anomaly
    utils_dir --> log
    utils_dir --> loss
    utils_dir --> opt
    utils_dir --> train_util

    static_dir --> static_css
    static_dir --> static_js
    static_dir --> static_img

    %% Cross-component relationships
    vd --> d_dir
    d_dir -->|data| train_py
    d_dir -->|data| test_py
    config_dir -->|settings| train_py
    config_dir -->|settings| test_py
    train_py -->|trains| model_dir
    train_py -->|uses| utils_dir
    test_py -->|evaluates| model_dir
    test_py -->|outputs| static_dir

    %% Click Events for Data Input / Pre-processing
    click d_dir "https://github.com/vt-le/astnet/tree/main/ASTNet/datasets"
    click ld "https://github.com/vt-le/astnet/blob/main/ASTNet/datasets/label_data.py"
    click vd_file "https://github.com/vt-le/astnet/blob/main/ASTNet/datasets/video_data.py"

    %% Click Events for Configuration Management
    click config_dir "https://github.com/vt-le/astnet/tree/main/ASTNet/config"
    click yaml1 "https://github.com/vt-le/astnet/blob/main/ASTNet/config/avenue_wresnet.yaml"
    click yaml2 "https://github.com/vt-le/astnet/blob/main/ASTNet/config/ped2_wresnet.yaml"
    click yaml3 "https://github.com/vt-le/astnet/blob/main/ASTNet/config/shanghaitech_wresnet.yaml"
    click defaults "https://github.com/vt-le/astnet/blob/main/ASTNet/config/defaults.py"

    %% Click Events for Model / Autoencoder Architecture
    click model_dir "https://github.com/vt-le/astnet/tree/main/ASTNet/models"
    click basic "https://github.com/vt-le/astnet/blob/main/ASTNet/models/basic_modules.py"
    click w_resnet "https://github.com/vt-le/astnet/blob/main/ASTNet/models/wider_resnet.py"
    click ws1024 "https://github.com/vt-le/astnet/blob/main/ASTNet/models/wresnet1024_cattn_tsm.py"
    click ws2048 "https://github.com/vt-le/astnet/blob/main/ASTNet/models/wresnet2048_multiscale_cattn_tsmplus_layer6.py"

    %% Click Events for Training Pipeline
    click train_py "https://github.com/vt-le/astnet/blob/main/ASTNet/train.py"

    %% Click Events for Evaluation Pipeline
    click test_py "https://github.com/vt-le/astnet/blob/main/ASTNet/test.py"

    %% Click Events for Utility Functions
    click utils_dir "https://github.com/vt-le/astnet/tree/main/ASTNet/utils"
    click anomaly "https://github.com/vt-le/astnet/blob/main/ASTNet/utils/anomaly_util.py"
    click log "https://github.com/vt-le/astnet/blob/main/ASTNet/utils/log_util.py"
    click loss "https://github.com/vt-le/astnet/blob/main/ASTNet/utils/loss_util.py"
    click opt "https://github.com/vt-le/astnet/blob/main/ASTNet/utils/optimizer_util.py"
    click train_util "https://github.com/vt-le/astnet/blob/main/ASTNet/utils/train_util.py"

    %% Click Events for Visualization / Static Assets
    click static_dir "https://github.com/vt-le/astnet/tree/main/static"
    click static_css "https://github.com/vt-le/astnet/tree/main/static/css"
    click static_js "https://github.com/vt-le/astnet/tree/main/static/js"
    click static_img "https://github.com/vt-le/astnet/tree/main/static/img"

    %% Styles
    classDef input fill:#cdf,stroke:#036,stroke-width:2px;
    classDef config fill:#fcf,stroke:#933,stroke-width:2px;
    classDef model fill:#dfd,stroke:#393,stroke-width:2px;
    classDef utils fill:#ffd,stroke:#996,stroke-width:2px;
    classDef pipeline fill:#fdd,stroke:#933,stroke-width:2px;
    classDef visual fill:#ddf,stroke:#339,stroke-width:2px;
```
