# yassineerraji/industrial-visual-defect-detection-anomaly-segmentation architecture

> Architecture diagram of the GitHub repository yassineerraji/industrial-visual-defect-detection-anomaly-segmentation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation
- Repository: https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation

## Overview

This repository compares industrial defect-detection models across normal-only anomaly detection and pixel-supervised segmentation. The main workflow prepares MVTec AD 2 data, trains models under distinct protocols, evaluates predictions and operational robustness, then packages models for inference through a reusable predictor and Streamlit demo. The README also documents MLflow tracking and release bundles. The graph follows sampled call paths where available; some evaluation, reporting, and demo details are based on documented capabilities and directory paths.

Main entry points: [`src/defect_detection/training/pipeline.py`](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/pipeline.py) (Normal-only training), [`src/defect_detection/evaluation/pipeline.py`](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/pipeline.py) (Evaluation pipeline), [`src/defect_detection/training/supervised.py`](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/supervised.py) (Supervised CV training), [`src/defect_detection/data/dataset.py`](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/dataset.py) (Dataset indexing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_dataset["Dataset indexing<br/>[dataset.py]"]
  node_preprocess["Preprocessing<br/>[preprocessing.py]"]
  node_augment["Augmentation<br/>[augmentations.py]"]
  node_folds["Grouped folds<br/>[folds.py]"]
  node_validation["Data validation<br/>[validation.py]"]
end

subgraph group_models["Model training"]
  node_normal_train["Normal-only training<br/>[pipeline.py]"]
  node_supervised_train["Supervised CV training<br/>[supervised.py]"]
  node_trainer["Gradient trainer<br/>[trainer.py]"]
  node_model_factory["Model implementations<br/>[__init__.py]"]
  node_runs[("Run artifacts<br/>[runs.py]")]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Evaluation pipeline<br/>[pipeline.py]"]
  node_scoring["Anomaly scoring<br/>[scoring.py]"]
  node_thresholds["Threshold selection<br/>[thresholds.py]"]
  node_metrics["Metrics and reports<br/>[metrics.py]"]
  node_robustness["Robustness evaluation<br/>[robustness.py]"]
end

subgraph group_deployment["Deployment"]
  node_release["Release bundles<br/>[release.py]"]
  node_predictor["Inference predictor<br/>[predictor.py]"]
  node_demo["Streamlit demo<br/>[streamlit_app.py]"]
end

subgraph group_tracking["Experiment tracking"]
  node_mlflow["MLflow tracking<br/>[tracking.py]"]
end

node_engineer(("Engineer"))
node_mvtec[("MVTec AD 2")]
node_mlflow_service[("MLflow backend")]

node_engineer -->|"validates data"| node_validation
node_mvtec -->|"provides images"| node_dataset
node_dataset -->|"checks structure"| node_validation
node_dataset -->|"loads samples"| node_preprocess
node_preprocess -->|"transforms training"| node_augment
node_engineer -->|"starts training"| node_normal_train
node_normal_train -->|"indexes splits"| node_dataset
node_normal_train -->|"builds transforms"| node_preprocess
node_normal_train -->|"builds model"| node_model_factory
node_normal_train -->|"fits model"| node_trainer
node_normal_train -->|"selects thresholds"| node_thresholds
node_normal_train -->|"scores validation"| node_scoring
node_normal_train -->|"saves run"| node_runs
node_engineer -->|"starts CV training"| node_supervised_train
node_supervised_train -->|"indexes samples"| node_dataset
node_supervised_train -->|"groups parts"| node_folds
node_supervised_train -->|"builds transforms"| node_preprocess
node_supervised_train -->|"builds models"| node_model_factory
node_supervised_train -->|"trains folds"| node_trainer
node_supervised_train -->|"saves folds"| node_runs
node_engineer -->|"evaluates run"| node_evaluation
node_evaluation -->|"loads config"| node_runs
node_evaluation -->|"indexes split"| node_dataset
node_evaluation -->|"loads model"| node_model_factory
node_evaluation -->|"computes maps"| node_scoring
node_evaluation -->|"loads thresholds"| node_thresholds
node_evaluation -->|"computes metrics"| node_metrics
node_engineer -->|"tests robustness"| node_robustness
node_robustness -->|"predicts conditions"| node_evaluation
node_robustness -->|"indexes split"| node_dataset
node_robustness -->|"applies perturbations"| node_preprocess
node_engineer -->|"exports run"| node_release
node_release -->|"reads run artifacts"| node_runs
node_release -->|"loads predictor"| node_predictor
node_engineer -->|"inspects image"| node_demo
node_demo -->|"requests predictions"| node_predictor
node_predictor -->|"transforms image"| node_preprocess
node_predictor -->|"scores anomaly map"| node_scoring
node_predictor -->|"loads model"| node_model_factory
node_engineer -->|"logs experiment"| node_mlflow
node_mlflow -->|"reads run records"| node_runs
node_mlflow -.->|"logs metrics"| node_mlflow_service

click node_dataset "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/dataset.py"
click node_preprocess "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/preprocessing.py"
click node_augment "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/augmentations.py"
click node_folds "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/folds.py"
click node_validation "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/validation.py"
click node_normal_train "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/pipeline.py"
click node_supervised_train "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/supervised.py"
click node_trainer "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/trainer.py"
click node_model_factory "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/models/__init__.py"
click node_runs "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/runs.py"
click node_evaluation "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/pipeline.py"
click node_scoring "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/scoring.py"
click node_thresholds "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/thresholds.py"
click node_metrics "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/metrics.py"
click node_robustness "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/robustness.py"
click node_release "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/release.py"
click node_predictor "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/inference/predictor.py"
click node_demo "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/app/streamlit_app.py"
click node_mlflow "https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/tracking.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset,node_preprocess,node_augment,node_folds,node_validation toneBlue
class node_normal_train,node_supervised_train,node_trainer,node_model_factory,node_runs,node_mvtec,node_mlflow_service toneAmber
class node_evaluation,node_scoring,node_thresholds,node_metrics,node_robustness toneMint
class node_release,node_predictor,node_demo toneRose
class node_mlflow,node_engineer toneIndigo
```

## Components

### Data preparation

- [Dataset indexing](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/dataset.py): `src/defect_detection/data/dataset.py`
- [Preprocessing](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/preprocessing.py): `src/defect_detection/data/preprocessing.py`
- [Augmentation](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/augmentations.py): `src/defect_detection/data/augmentations.py`
- [Grouped folds](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/folds.py): `src/defect_detection/data/folds.py`
- [Data validation](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/data/validation.py): `src/defect_detection/data/validation.py`

### Model training

- [Normal-only training](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/pipeline.py): `src/defect_detection/training/pipeline.py`
- [Supervised CV training](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/supervised.py): `src/defect_detection/training/supervised.py`
- [Gradient trainer](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/training/trainer.py): `src/defect_detection/training/trainer.py`
- [Model implementations](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/models/__init__.py): `src/defect_detection/models/__init__.py`
- [Run artifacts](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/runs.py): `src/defect_detection/runs.py`

### Evaluation

- [Evaluation pipeline](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/pipeline.py): `src/defect_detection/evaluation/pipeline.py`
- [Anomaly scoring](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/scoring.py): `src/defect_detection/evaluation/scoring.py`
- [Threshold selection](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/thresholds.py): `src/defect_detection/evaluation/thresholds.py`
- [Metrics and reports](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/metrics.py): `src/defect_detection/evaluation/metrics.py`
- [Robustness evaluation](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/evaluation/robustness.py): `src/defect_detection/evaluation/robustness.py`

### Deployment

- [Release bundles](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/release.py): `src/defect_detection/release.py`
- [Inference predictor](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/inference/predictor.py): `src/defect_detection/inference/predictor.py`
- [Streamlit demo](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/app/streamlit_app.py): `app/streamlit_app.py`

### Experiment tracking

- [MLflow tracking](https://github.com/yassineerraji/industrial-visual-defect-detection-anomaly-segmentation/blob/main/src/defect_detection/tracking.py): `src/defect_detection/tracking.py`

### Other components

- **Engineer**
- **MVTec AD 2**
- **MLflow backend**

## Connections

- Engineer → Data validation: validates data
- MVTec AD 2 → Dataset indexing: provides images
- Dataset indexing → Data validation: checks structure
- Dataset indexing → Preprocessing: loads samples
- Preprocessing → Augmentation: transforms training
- Engineer → Normal-only training: starts training
- Normal-only training → Dataset indexing: indexes splits
- Normal-only training → Preprocessing: builds transforms
- Normal-only training → Model implementations: builds model
- Normal-only training → Gradient trainer: fits model
- Normal-only training → Threshold selection: selects thresholds
- Normal-only training → Anomaly scoring: scores validation
- Normal-only training → Run artifacts: saves run
- Engineer → Supervised CV training: starts CV training
- Supervised CV training → Dataset indexing: indexes samples
- Supervised CV training → Grouped folds: groups parts
- Supervised CV training → Preprocessing: builds transforms
- Supervised CV training → Model implementations: builds models
- Supervised CV training → Gradient trainer: trains folds
- Supervised CV training → Run artifacts: saves folds
- Engineer → Evaluation pipeline: evaluates run
- Evaluation pipeline → Run artifacts: loads config
- Evaluation pipeline → Dataset indexing: indexes split
- Evaluation pipeline → Model implementations: loads model
- Evaluation pipeline → Anomaly scoring: computes maps
- Evaluation pipeline → Threshold selection: loads thresholds
- Evaluation pipeline → Metrics and reports: computes metrics
- Engineer → Robustness evaluation: tests robustness
- Robustness evaluation → Evaluation pipeline: predicts conditions
- Robustness evaluation → Dataset indexing: indexes split
- Robustness evaluation → Preprocessing: applies perturbations
- Engineer → Release bundles: exports run
- Release bundles → Run artifacts: reads run artifacts
- Release bundles → Inference predictor: loads predictor
- Engineer → Streamlit demo: inspects image
- Streamlit demo → Inference predictor: requests predictions
- Inference predictor → Preprocessing: transforms image
- Inference predictor → Anomaly scoring: scores anomaly map
- Inference predictor → Model implementations: loads model
- Engineer → MLflow tracking: logs experiment
- MLflow tracking → Run artifacts: reads run records
- MLflow tracking → MLflow backend: logs metrics
