# donaldrr/simplenet architecture

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

- Interactive diagram: https://gitdiagram.com/donaldrr/simplenet
- Repository: https://github.com/donaldrr/simplenet

## Overview

##### Main Components
- Data Layer:
- Datasets: The “datasets” folder contains multiple dataset modules (e.g., “btad”, “cifar10”, “mvtec”, “sdd”) that handle loading, processing, and potentially augmentation of image data. These modules abstract the dataset-specific logic.
- Model Architecture:
- Core Model Files: “simplenet.py”, “backbones.py”, “resnet.py”, and “common.py” together define the components of the defect detection network (feature encoder, generator, defect discriminator) as described in the README.
- Execution and Utility:
- “main.py”: Acts as the entry point for training, evaluation, or inference.
- “run.sh”: Provides a shell script to configure dataset paths, log directories, and start the training process.
- “metrics.py” and “utils.py”: Provide essential utilities and evaluation metrics that support the training and performance assessment.

- “Feature Encoder”: Represented by parts of “simplenet.py”, “backbones.py”, and possibly “resnet.py”.
- “Feature Generator”
- “Defect Discriminator”
- “Training & Evaluation”:
- External Components:
- A note for “PyTorch & Torchvision” as the underlying deep learning framework libraries.
- Optionally, include a “Configuration & Execution” block near the periphery to represent “run.sh” which ties together configuration details (like choosing a dataset, setting paths, and logging) and launching the process.

##### Architectural Patterns and Key Principles
- Modularity: The separation of dataset modules, model definition, and utilities reflects a modular design.
- Pipeline Flow: Emphasize the sequential data flow—from input images through preprocessing, feature extraction, generation, discrimination, and finally evaluation/training feedback.
- Reusability: The use of common components (common.py, utils.py) underscores design for reuse.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Data
    Input["Input Data (Raw Images)"]:::dataStyle

    %% Dataset Modules Subgraph
    subgraph "Dataset Modules"
        BTAD["BTAD"]:::datasetStyle
        CIFAR["CIFAR10"]:::datasetStyle
        MVTEC["MvTec"]:::datasetStyle
        SDD["SDD"]:::datasetStyle
        SDD2["SDD2"]:::datasetStyle
    end

    %% Data Loader / Preprocessing
    DataLoader["Data Loader/Preprocessing"]:::dataProcStyle

    %% Model Architecture Subgraph
    subgraph "Model Architecture"
        Encoder["Feature Encoder"]:::modelStyle
        Generator["Feature Generator"]:::modelStyle
        Discriminator["Defect Discriminator"]:::modelStyle
        Common["Common Modules"]:::modelStyle
    end

    %% Training Pipeline & Execution
    Training["Training Pipeline (main.py)"]:::executionStyle
    Config["Configuration & Execution (run.sh)"]:::executionStyle

    %% Evaluation & Utilities Subgraph
    subgraph "Evaluation & Utilities"
        Metrics["Metrics"]:::utilityStyle
        Utils["Utils"]:::utilityStyle
    end

    %% External Dependency
    External["PyTorch & Torchvision"]:::externalStyle

    %% Connections
    Input --> BTAD
    Input --> CIFAR
    Input --> MVTEC
    Input --> SDD
    Input --> SDD2

    BTAD --> DataLoader
    CIFAR --> DataLoader
    MVTEC --> DataLoader
    SDD --> DataLoader
    SDD2 --> DataLoader

    DataLoader --> Encoder
    Encoder --> Generator
    Encoder --> Discriminator
    %% (Common is a supporting module; no direct flow arrows)

    Encoder --> Training
    Generator --> Training
    Discriminator --> Training
    DataLoader --> Training

    Training --> Metrics
    Training --> Utils

    Config --> Training

    External --> Encoder

    %% Click Events
    click BTAD "https://github.com/donaldrr/simplenet/blob/main/datasets/btad.py"
    click CIFAR "https://github.com/donaldrr/simplenet/blob/main/datasets/cifar10.py"
    click MVTEC "https://github.com/donaldrr/simplenet/blob/main/datasets/mvtec.py"
    click SDD "https://github.com/donaldrr/simplenet/blob/main/datasets/sdd.py"
    click SDD2 "https://github.com/donaldrr/simplenet/blob/main/datasets/sdd2.py"
    click DataLoader "https://github.com/donaldrr/simplenet/tree/main/datasets/"
    click Encoder "https://github.com/donaldrr/simplenet/blob/main/simplenet.py"
    click Generator "https://github.com/donaldrr/simplenet/blob/main/backbones.py"
    click Discriminator "https://github.com/donaldrr/simplenet/blob/main/resnet.py"
    click Common "https://github.com/donaldrr/simplenet/blob/main/common.py"
    click Training "https://github.com/donaldrr/simplenet/blob/main/main.py"
    click Config "https://github.com/donaldrr/simplenet/blob/main/run.sh"
    click Metrics "https://github.com/donaldrr/simplenet/blob/main/metrics.py"
    click Utils "https://github.com/donaldrr/simplenet/blob/main/utils.py"

    %% Styles
    classDef dataStyle fill:#f9e79f,stroke:#a04000,stroke-width:2px;
    classDef datasetStyle fill:#fad7a0,stroke:#a04000,stroke-width:2px;
    classDef dataProcStyle fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef modelStyle fill:#a9dfbf,stroke:#196f3d,stroke-width:2px;
    classDef executionStyle fill:#f5b7b1,stroke:#943126,stroke-width:2px;
    classDef utilityStyle fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef externalStyle fill:#f7dc6f,stroke:#b7950b,stroke-width:2px;
```
