# whjdark/aagnet architecture

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

- Interactive diagram: https://gitdiagram.com/whjdark/aagnet
- Repository: https://github.com/whjdark/aagnet

## Overview

##### Main Components to Identify
a. Input/Data Processing:
- Dataset Creation and Conversion: The “dataset” directory includes modules (e.g., AAGExtractor, Features, OCCUtils, and Utils) which are responsible for extracting and managing geometric, topological, and extended attributes from STEP/B-Rep files.
- Data Loading: The “dataloader” folder provides multiple variants (e.g., mfcad, mfinstseg) for reading and preprocessing the raw data.
- Dataset Partitions: “MFInstseg_partition” houses text files that likely serve as train/validation/test splits.
b. Model:
- Neural Network Components: The “models” directory includes definitions for encoders, decoders, segmentation heads, and the network’s auxiliary layers (activations, loss functions, etc.). This is where the main AAGNet architecture is defined.
- Additional Modeling Utilities: The “ASIN_for_MFInstSeg” sub-module contains additional model scripts likely tailored to working with the MFInstSeg dataset.
c. Training & Inference Engine:
- The “engine” folder holds trainer and tester scripts (e.g., seg_trainer.py, inst_trainer.py, inst_test.py, inst_test_per_feature_metric.py) which drive the training and evaluation pipelines.
d. Visualization and Evaluation:
- “utils” contains various utility scripts for post-processing and visualization (e.g., qt5_visualization, step2stl, visualize_uv), and additional performance testing (e.g., infer_speed_test).
e. Supporting Components:
- “environment.yml” provides the computational environment information, demonstrating dependencies on PyTorch, DGL, pythonocc-core, and other libraries.

##### Relationships and Interactions
- Data flows from raw STEP/B-Rep files through the dataset extraction pipelines (in “dataset” and “dataloader” modules) to produce the gAAG inputs.
- These inputs are fed into the model, which is comprised of distinct stages: an “input encoder” (extracting basic features), a “graph encoder” (leveraging GNNs to capture spatial and topological relationships), and a “multi-task head” that produces segmentation outputs.
- Training and evaluation are performed via scripts in the “engine” directory, where configuration and dataset paths are defined.
- There is a clear separation between training, testing, and inference components with dedicated utilities making the system modular and testable.

##### Architectural Patterns and Key Design Principles
- Modular Organization: The separation into dataset handling, modeling, training, and testing modules illustrates a clean modular design.
- Multi-task Learning: The network is designed to support simultaneous tasks, as evident in the multi-task head architecture.
- Graph Neural Network (GNN) Concepts: The central idea is processing graph-based representations (gAAG) that maintain geometric, topological, and attribute information.
- Data Pipelines: There’s a well-demarcated pipeline from raw data through conversion to training-ready formats (gAAG), giving room to easily swap datasets (MFCAD, MFCAD++, MFInstSeg) via configuration changes.

##### Relevant Technologies & Libraries
- PyTorch is used as the primary deep learning framework.
- DGL (Deep Graph Library) indicates that the models make use of graph processing capabilities.
- pythonocc-core and occt are crucial for CAD model manipulation and geometric processing.
- Numba for potential acceleration of numerical/geometric computations.
- Supporting libraries like scikit-learn, timm, wandb, and torchmetrics for evaluation, model checkpointing and experiment tracking.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Source
    RawData("Raw Data: STEP/B-Rep"):::data

    %% Dataset Preparation Block
    subgraph "Dataset Preparation"
        subgraph "Data Extraction"
            AAG("AAGExtractor"):::data
            FEAT("Features"):::data
            OCC("OCCUtils"):::data
            DUT("Utils"):::data
        end
        DataLoading("Data Loading"):::data
        DatasetPartition("Dataset Partition"):::data
        Preprocessed("Preprocessed Data"):::data
    end

    %% Model Architecture Block
    subgraph "Model Architecture"
        H1("Models"):::model
        H2("ASIN Models"):::model
        InputEncoder("Input Encoder"):::model
        GraphEncoder("Graph Encoder"):::model
        MultiTaskHead("Multi-task Head"):::model
        AdditionalUtilities("Additional Modeling Utilities"):::model
    end

    %% Training & Inference Engine Block
    subgraph "Training & Inference Engine"
        TrainingEngine("Training Engine"):::engine
    end

    %% Testing & Visualization Block
    subgraph "Testing & Visualization"
        Visualization("Visualization & Evaluation"):::utils
    end

    %% Support Block (Documentation & Environment)
    subgraph "Support"
        Documentation("Documentation"):::docs
        EnvConfig("Environment Config"):::docs
    end

    %% Connections
    RawData --> AAG
    RawData --> FEAT
    RawData --> OCC
    RawData --> DUT

    AAG --> DataLoading
    FEAT --> DataLoading
    OCC --> DataLoading
    DUT --> DataLoading

    DataLoading --> Preprocessed
    DatasetPartition --> Preprocessed

    Preprocessed --> InputEncoder
    H1 --> InputEncoder
    H2 --> InputEncoder
    InputEncoder --> GraphEncoder
    GraphEncoder --> MultiTaskHead
    AdditionalUtilities --> MultiTaskHead

    MultiTaskHead --> TrainingEngine
    TrainingEngine --> Visualization
    TrainingEngine --> Documentation
    TrainingEngine --> EnvConfig

    %% Click Events
    click AAG "https://github.com/whjdark/aagnet/blob/main/dataset/AAGExtractor.py"
    click FEAT "https://github.com/whjdark/aagnet/tree/main/dataset/Features"
    click OCC "https://github.com/whjdark/aagnet/tree/main/dataset/OCCUtils"
    click DUT "https://github.com/whjdark/aagnet/tree/main/dataset/Utils"
    click DataLoading "https://github.com/whjdark/aagnet/tree/main/dataloader"
    click DatasetPartition "https://github.com/whjdark/aagnet/tree/main/MFInstseg_partition"
    click H1 "https://github.com/whjdark/aagnet/tree/main/models"
    click H2 "https://github.com/whjdark/aagnet/tree/main/ASIN_for_MFInstSeg/models"
    click AdditionalUtilities "https://github.com/whjdark/aagnet/tree/main/ASIN_for_MFInstSeg"
    click TrainingEngine "https://github.com/whjdark/aagnet/tree/main/engine"
    click Visualization "https://github.com/whjdark/aagnet/tree/main/utils"
    click Documentation "https://github.com/whjdark/aagnet/tree/main/docs"
    click EnvConfig "https://github.com/whjdark/aagnet/blob/main/environment.yaml"

    %% Styles
    classDef data fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef model fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef engine fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef utils fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef docs fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
```
