# rapidonot/wafer-defect-classifier architecture

> Architecture diagram of the GitHub repository rapidonot/wafer-defect-classifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rapidonot/wafer-defect-classifier
- Repository: https://github.com/rapidonot/wafer-defect-classifier

## Overview

This repository builds a multi-label wafer-bin-map defect classifier and provides a Streamlit image-upload demo. The user workflow is upload an image, convert it to the model’s categorical input, run ResNet-18 inference, then view confidence scores and thresholded defect labels. Separate workflows prepare datasets, train ResNet-18 or Vanilla CNN models with BCE or focal loss, and benchmark predictions. The tree and excerpts support these major capabilities, but do not establish that training produces the dashboard’s bundled weights or that the evaluation model path exists.

Main entry points: [`code /split_data.py`](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/split_data.py) (Dataset preparation), [`dashboard/app.py`](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py) (Streamlit interface), [`code /modeltraining.py`](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/modeltraining.py) (Model training), [`dashboard/model_utils.py`](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/model_utils.py) (Wafer classifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_demo["Classifier demo"]
  node_dashboard["Streamlit interface<br/>[app.py]"]
  node_image_conversion["Image conversion<br/>[app.py]"]
  node_classifier["Wafer classifier<br/>[model_utils.py]"]
  node_resnet_weights["ResNet weights<br/>[resnet18_bce.pth]"]
  node_results["Scores and chart<br/>[app.py]"]
end

subgraph group_ml["Data and training"]
  node_wm811k["WM-811k source"]
  node_mixedwm["MixedWM38 source"]
  node_split["Dataset preparation<br/>[split_data.py]"]
  node_train_data["Training split"]
  node_validation_data["Validation split<br/>[dataset_15_VAL.npz]"]
  node_trainer["Model training<br/>[modeltraining.py]"]
  node_trained_weights["Training checkpoints<br/>[modeltraining.py]"]
end

subgraph group_evaluation["Model evaluation"]
  node_test_data["Test split"]
  node_benchmark["Benchmark evaluation<br/>[benchmarking.py]"]
  node_evaluation_report["Metrics and plots<br/>[benchmarking.py]"]
end

node_user(("Image uploader"))

node_user -->|"uploads image"| node_dashboard
node_dashboard -->|"converts image"| node_image_conversion
node_dashboard -->|"calls predict"| node_classifier
node_classifier -->|"loads weights"| node_resnet_weights
node_classifier -->|"returns scores"| node_results
node_dashboard -->|"thresholds and charts"| node_results
node_wm811k -->|"loads dataset"| node_split
node_mixedwm -->|"loads dataset"| node_split
node_split -->|"writes split"| node_train_data
node_split -->|"writes split"| node_validation_data
node_split -->|"writes split"| node_test_data
node_trainer -->|"loads training data"| node_train_data
node_trainer -->|"loads validation data"| node_validation_data
node_trainer -->|"saves best checkpoint"| node_trained_weights
node_benchmark -->|"loads test data"| node_test_data
node_benchmark -->|"reports metrics"| node_evaluation_report

click node_dashboard "https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py"
click node_image_conversion "https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py"
click node_classifier "https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/model_utils.py"
click node_resnet_weights "https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/resnet18_bce.pth"
click node_results "https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py"
click node_split "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/split_data.py"
click node_train_data "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/dataset_70_TRAIN.npz"
click node_validation_data "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/dataset_15_VAL.npz"
click node_test_data "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/dataset_15_TEST.npz"
click node_trainer "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/modeltraining.py"
click node_trained_weights "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/modeltraining.py"
click node_benchmark "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/benchmarking.py"
click node_evaluation_report "https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/benchmarking.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_dashboard,node_image_conversion,node_classifier,node_resnet_weights,node_results toneBlue
class node_wm811k,node_mixedwm,node_split,node_train_data,node_validation_data,node_trainer,node_trained_weights toneAmber
class node_test_data,node_benchmark,node_evaluation_report toneMint
class node_user toneIndigo
```

## Components

### Classifier demo

- [Streamlit interface](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py): `dashboard/app.py`
- [Image conversion](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py): `dashboard/app.py`
- [Wafer classifier](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/model_utils.py): `dashboard/model_utils.py`
- [ResNet weights](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/resnet18_bce.pth): `dashboard/resnet18_bce.pth`
- [Scores and chart](https://github.com/rapidonot/wafer-defect-classifier/blob/main/dashboard/app.py): `dashboard/app.py`

### Data and training

- **WM-811k source**
- **MixedWM38 source**
- [Dataset preparation](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/split_data.py): `code /split_data.py`
- [Training split](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/dataset_70_TRAIN.npz): `code /dataset_70_TRAIN.npz`
- [Validation split](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/dataset_15_VAL.npz): `code /dataset_15_VAL.npz`
- [Model training](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/modeltraining.py): `code /modeltraining.py`
- [Training checkpoints](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/modeltraining.py): `code /modeltraining.py`

### Model evaluation

- [Test split](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/dataset_15_TEST.npz): `code /dataset_15_TEST.npz`
- [Benchmark evaluation](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/benchmarking.py): `code /benchmarking.py`
- [Metrics and plots](https://github.com/rapidonot/wafer-defect-classifier/blob/main/code%20/benchmarking.py): `code /benchmarking.py`

### Other components

- **Image uploader**

## Connections

- Image uploader → Streamlit interface: uploads image
- Streamlit interface → Image conversion: converts image
- Streamlit interface → Wafer classifier: calls predict
- Wafer classifier → ResNet weights: loads weights
- Wafer classifier → Scores and chart: returns scores
- Streamlit interface → Scores and chart: thresholds and charts
- WM-811k source → Dataset preparation: loads dataset
- MixedWM38 source → Dataset preparation: loads dataset
- Dataset preparation → Training split: writes split
- Dataset preparation → Validation split: writes split
- Dataset preparation → Test split: writes split
- Model training → Training split: loads training data
- Model training → Validation split: loads validation data
- Model training → Training checkpoints: saves best checkpoint
- Benchmark evaluation → Test split: loads test data
- Benchmark evaluation → Metrics and plots: reports metrics
