# nelson1425/efficientad architecture

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

- Interactive diagram: https://gitdiagram.com/nelson1425/efficientad
- Repository: https://github.com/nelson1425/efficientad

## Overview

##### Project Type and Purpose
- EfficientAD is an open-source Python toolkit for visual anomaly detection, implementing the methods from “EfficientAD: Accurate Visual Anomaly Detection” (arXiv:2303.14535).
- It provides training, inference, benchmarking, and evaluation pipelines on datasets like MVTec AD and MVTec LOCO, optionally leveraging ImageNet for pretraining.

##### File Structure
- Top-level scripts:
- efficientad.py – main entry point for training and inference
- pretraining.py – standalone pretraining routine using general images
- benchmark.py – measures model latency throughput
- Utilities:
- common.py – shared helper functions (data loading, metric computation, CLI parsing)
- Models directory: stores pretrained weights (teacher_small.pth, teacher_medium.pth)
- Results directory: contains JSON metrics outputs
- Ancillary files: LICENSE, README.md

##### Extract Additional Insights from README
- Describes supported datasets (Mvtec AD, Mvtec LOCO) and evaluation workflows.
- Specifies dependency stack (Python 3.10, PyTorch, torchvision, scikit-learn, tifffile).
- Outlines CLI arguments for dataset paths, model size, and weight selection.
- Details external evaluation scripts (not part of repo) that consume anomaly maps and produce metrics.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "Data Sources"
        DS1["MVTec AD / LOCO Datasets"]:::storage
        DS2["ImageNet Folder"]:::storage
    end

    %% Core Modules
    subgraph "Core Modules"
        CLI["CLI Parser & Trainer\n(efficientad.py)"]:::cli
        Pretrain["Pretraining Pipeline\n(pretraining.py)"]:::process
        DataLoader["Data Loader & Preprocessor\n(common.py)"]:::process
        Benchmark["Benchmark Runner\n(benchmark.py)"]:::process
    end

    %% Storage / Artifacts
    subgraph "Storage / Artifacts"
        Models["Model Weights Storage\n(models/)"]:::storage
        WeightsMedium["teacher_medium.pth"]:::storage
        WeightsSmall["teacher_small.pth"]:::storage
        Results["Anomaly Maps & Metrics\n(results/)"]:::storage
        MetricMed["mvtec_ad_medium.json"]:::storage
        MetricSmall["mvtec_ad_small.json"]:::storage
    end

    %% Documentation
    subgraph "Documentation"
        README["README.md"]:::doc
        LICENSE["LICENSE"]:::doc
    end

    %% External Integrations
    External["External Evaluation Scripts"]:::external

    %% Data Flows
    DS1 -->|images| DataLoader
    DS2 -->|images| Pretrain
    CLI -->|"selects mode"| Pretrain
    CLI -->|"selects mode"| DataLoader
    DataLoader -->|"batches images"| CLI
    Pretrain -->|"outputs weights"| Models
    CLI -->|"loads weights"| Models
    CLI -->|"produces anomaly maps & metrics"| Results
    Benchmark -->|"loads weights"| Models
    Benchmark -->|samples from| DS1
    Results -->|"consumed by"| External
    CLI -->|"uses utilities"| DataLoader
    Pretrain -->|"uses utilities"| DataLoader
    Benchmark -->|"uses utilities"| DataLoader

    %% Click Events
    click CLI "https://github.com/nelson1425/efficientad/blob/main/efficientad.py"
    click Pretrain "https://github.com/nelson1425/efficientad/blob/main/pretraining.py"
    click Benchmark "https://github.com/nelson1425/efficientad/blob/main/benchmark.py"
    click DataLoader "https://github.com/nelson1425/efficientad/blob/main/common.py"
    click Models "https://github.com/nelson1425/efficientad/tree/main/models/"
    click WeightsMedium "https://github.com/nelson1425/efficientad/blob/main/models/teacher_medium.pth"
    click WeightsSmall "https://github.com/nelson1425/efficientad/blob/main/models/teacher_small.pth"
    click Results "https://github.com/nelson1425/efficientad/tree/main/results/"
    click MetricMed "https://github.com/nelson1425/efficientad/blob/main/results/mvtec_ad_medium.json"
    click MetricSmall "https://github.com/nelson1425/efficientad/blob/main/results/mvtec_ad_small.json"
    click README "https://github.com/nelson1425/efficientad/blob/main/README.md"
    click LICENSE "https://github.com/nelson1425/efficientad/tree/main/LICENSE"

    %% Styles
    classDef storage fill:#9cf,stroke:#333,stroke-width:1px
    classDef cli fill:#fea,stroke:#333,stroke-width:1px
    classDef process fill:#8f8,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
    classDef doc fill:#ffc,stroke:#333,stroke-width:1px
```
