# arimousa/ddad architecture

> Architecture diagram of the GitHub repository arimousa/ddad, 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/arimousa/ddad
- Repository: https://github.com/arimousa/ddad

## Overview

This project is a research-oriented anomaly detection system that implements Conditioned Denoising Diffusion Models (DDAD) using PyTorch. The overall purpose is to train and evaluate models designed for detecting and localizing anomalies in image datasets (e.g., MVTec AD and VisA).

##### Main Components
- Data Handling & Preprocessing: Represent the module “dataset.py” which is responsible for loading and preparing the image datasets (as detailed in the README). You may also want to indicate how configuration settings from “config.yaml” influence this stage.
- Model Architecture and Core Algorithms: Highlight “ddad.py”, “unet.py”, “resnet.py”, and “feature_extractor.py”. These files indicate the various network components and feature extraction modules used to define the Conditioned Denoising Diffusion Model.
- Loss and Metrics Computation: Include “loss.py” and “metrics.py” which handle the loss functions and evaluation metrics necessary for both training and evaluating the anomaly detection performance.
- Training & Evaluation Pipeline: Mark “main.py” and “train.py” as the central scripts that orchestrate model training, domain adaptation (as per the README’s instructions), and detection/evaluation. These scripts tie all modules together.

##### Relationships and Interactions
- That the computed outputs feed into loss (loss.py) and metric computations (metrics.py), and finally, the results are routed to visualization modules.
- That training runs involve checkpointing and evaluation steps, as mentioned in the README (with data coming from external sources such as the provided datasets and checkpoints).

##### Architectural Patterns and Principles
- Modular Design: Each file encapsulates a distinct responsibility (data, model, loss, metric evaluation, etc.). This separation is key for clarity.
- Pipeline Flow: The project simulates a sequential “data -> model -> loss/metrics -> results visualization” workflow, an important pattern in deep learning projects.
- Configuration-driven: The use of “config.yaml” along with command-line flags in main.py makes it easy to switch between training modes (standard training, domain adaptation, detection), so denote this flexibility.

##### Relevant Technologies and Frameworks
- Python 3.8 and PyTorch 2.1: Clearly label these as part of your “Environment/Framework” node.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Input & Configuration"
        Config["config.yaml"]:::config
        CLI["Command-line_Flags"]:::config
    end

    subgraph "Training & Evaluation Pipeline"
        TP["main.py, train.py"]:::pipeline
    end

    subgraph "Data Handling & Preprocessing"
        DH["dataset.py"]:::data
    end

    subgraph "Model Components"
        DDAD["ddad.py"]:::model
        UNET["unet.py"]:::model
        RESNET["resnet.py"]:::model
        FEAT["feature_extractor.py"]:::model
    end

    subgraph "Loss & Metrics Computation"
        LOSS["loss.py"]:::loss
        METRICS["metrics.py"]:::loss
    end

    subgraph "Visualization & Post-processing"
        VIS["visualize.py"]:::viz
        AM["anomaly_map.py"]:::viz
    end

    subgraph "Supporting Files"
        LIC["LICENSE"]:::support
        README["README.md"]:::support
        REQ["requirements.txt"]:::support
        IMG["images"]:::support
    end

    ENV["Python 3.8 & PyTorch 2.1"]:::env

    Config --> TP
    CLI --> TP
    TP --> DH
    DH --> DDAD
    DDAD --> UNET
    DDAD --> RESNET
    DDAD --> FEAT
    DDAD --> LOSS
    DDAD --> METRICS
    LOSS --> VIS
    METRICS --> VIS
    ENV --> TP

    classDef config fill:#bde0fe,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#ffe066,stroke:#333,stroke-width:2px;
    classDef data fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef model fill:#ffadad,stroke:#333,stroke-width:2px;
    classDef loss fill:#ffd6a5,stroke:#333,stroke-width:2px;
    classDef viz fill:#9bf6ff,stroke:#333,stroke-width:2px;
    classDef support fill:#cdb4db,stroke:#333,stroke-width:2px;
    classDef env fill:#ffffb3,stroke:#333,stroke-width:2px;

    click Config "https://github.com/arimousa/ddad/blob/main/config.yaml"
    click DH "https://github.com/arimousa/ddad/blob/main/dataset.py"
    click DDAD "https://github.com/arimousa/ddad/blob/main/ddad.py"
    click UNET "https://github.com/arimousa/ddad/blob/main/unet.py"
    click RESNET "https://github.com/arimousa/ddad/blob/main/resnet.py"
    click FEAT "https://github.com/arimousa/ddad/blob/main/feature_extractor.py"
    click LOSS "https://github.com/arimousa/ddad/blob/main/loss.py"
    click METRICS "https://github.com/arimousa/ddad/blob/main/metrics.py"
    click TP "https://github.com/arimousa/ddad/blob/main/main.py"
    click VIS "https://github.com/arimousa/ddad/blob/main/visualize.py"
    click AM "https://github.com/arimousa/ddad/blob/main/anomaly_map.py"
    click LIC "https://github.com/arimousa/ddad/tree/main/LICENSE"
    click README "https://github.com/arimousa/ddad/blob/main/README.md"
    click REQ "https://github.com/arimousa/ddad/blob/main/requirements.txt"
    click IMG "https://github.com/arimousa/ddad/tree/main/images"
```
