# witchcraftcode/crackdetection architecture

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

- Interactive diagram: https://gitdiagram.com/witchcraftcode/crackdetection
- Repository: https://github.com/witchcraftcode/crackdetection

## Overview

This repository provides a concrete-crack image classifier and inspection toolkit. Its main workflow trains a binary classifier from labeled images, saves a model, then serves predictions through an image-upload API or runs them from scripts. The README also documents video, explanation, segmentation, edge export, drone simulation, architecture benchmarking, and metrics evaluation. The graph includes those distinct capabilities; connections for unsampled script internals rely on README documentation or SOURCE INDEX references, not inspected implementations.

Main entry points: [`src/inference.py`](https://github.com/witchcraftcode/crackdetection/blob/main/src/inference.py) (Image Inference), [`scripts/train_classifier.py`](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/train_classifier.py) (Classifier Training), [`scripts/segment_cracks.py`](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/segment_cracks.py) (Attention Masks), [`model.py`](https://github.com/witchcraftcode/crackdetection/blob/main/model.py) (Cached Model Helper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Model Training"]
  node_classifier_training["Classifier Training"]
  node_classifier_architectures["Classifier Architectures<br/>[architectures.py]"]
  node_classifier_model["Trained Classifier"]
end

subgraph group_inference["Prediction Interfaces"]
  node_api["Prediction API<br/>[app.py]"]
  node_cached_model["Cached Model Helper<br/>[model.py]"]
  node_inference_core["Image Inference<br/>[inference.py]"]
end

subgraph group_inspection["Inspection Tools"]
  node_video_inference["Video Inference<br/>[video_inference.py]"]
  node_explain_image["Image Explanations<br/>[explain_image.py]"]
  node_pseudo_segmentation["Attention Masks<br/>[segment_cracks.py]"]
  node_segmentation_training["Segmenter Training"]
  node_segmentation_model["U-Net Architecture<br/>[segmentation.py]"]
  node_drone_simulation["Drone Simulation"]
end

subgraph group_evaluation["Evaluation and Deployment"]
  node_metrics_evaluation["Metrics Evaluation"]
  node_architecture_benchmark["Architecture Benchmark"]
  node_edge_export["Edge Model Export"]
end

node_dataset["Labeled Images"]
node_api_client(("API Client"))
node_image_user(("Image User"))

node_dataset -->|"trains on"| node_classifier_training
node_classifier_training -->|"selects architecture"| node_classifier_architectures
node_classifier_training -->|"saves model"| node_classifier_model
node_api_client -->|"uploads image"| node_api
node_image_user -->|"requests prediction"| node_inference_core
node_api -->|"calls prediction"| node_cached_model
node_cached_model -->|"loads and predicts"| node_inference_core
node_classifier_model -->|"loaded by"| node_cached_model
node_classifier_model -->|"loads for frames"| node_video_inference
node_video_inference -->|"loads model"| node_inference_core
node_classifier_model -->|"explained by"| node_explain_image
node_explain_image -->|"loads and preprocesses"| node_inference_core
node_classifier_model -->|"generates attention mask"| node_pseudo_segmentation
node_pseudo_segmentation -->|"uses Grad-CAM"| node_explain_image
node_pseudo_segmentation -->|"loads and preprocesses"| node_inference_core
node_dataset -->|"provides paired images and masks"| node_segmentation_training
node_segmentation_training -->|"builds U-Net"| node_segmentation_model
node_classifier_model -->|"used for inspection"| node_drone_simulation
node_drone_simulation -->|"uses prediction"| node_inference_core
node_classifier_model -->|"evaluated by"| node_metrics_evaluation
node_metrics_evaluation -->|"uses preprocessing"| node_inference_core
node_classifier_architectures -->|"benchmarked by"| node_architecture_benchmark
node_classifier_model -->|"exports for edge"| node_edge_export

click node_classifier_training "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/train_classifier.py"
click node_classifier_architectures "https://github.com/witchcraftcode/crackdetection/blob/main/src/architectures.py"
click node_api "https://github.com/witchcraftcode/crackdetection/blob/main/app.py"
click node_cached_model "https://github.com/witchcraftcode/crackdetection/blob/main/model.py"
click node_inference_core "https://github.com/witchcraftcode/crackdetection/blob/main/src/inference.py"
click node_video_inference "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/video_inference.py"
click node_explain_image "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/explain_image.py"
click node_pseudo_segmentation "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/segment_cracks.py"
click node_segmentation_training "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/train_segmentation.py"
click node_segmentation_model "https://github.com/witchcraftcode/crackdetection/blob/main/src/segmentation.py"
click node_drone_simulation "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/drone_inspection_sim.py"
click node_metrics_evaluation "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/evaluate_metrics.py"
click node_architecture_benchmark "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/benchmark_architectures.py"
click node_edge_export "https://github.com/witchcraftcode/crackdetection/blob/main/scripts/export_edge_model.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_classifier_training,node_classifier_architectures,node_classifier_model,node_api_client,node_image_user toneBlue
class node_api,node_cached_model,node_inference_core toneAmber
class node_video_inference,node_explain_image,node_pseudo_segmentation,node_segmentation_training,node_segmentation_model,node_drone_simulation toneMint
class node_metrics_evaluation,node_architecture_benchmark,node_edge_export toneRose
class node_dataset toneIndigo
```

## Components

### Model Training

- [Classifier Training](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/train_classifier.py): `scripts/train_classifier.py`
- [Classifier Architectures](https://github.com/witchcraftcode/crackdetection/blob/main/src/architectures.py): `src/architectures.py`
- **Trained Classifier**

### Prediction Interfaces

- [Prediction API](https://github.com/witchcraftcode/crackdetection/blob/main/app.py): `app.py`
- [Cached Model Helper](https://github.com/witchcraftcode/crackdetection/blob/main/model.py): `model.py`
- [Image Inference](https://github.com/witchcraftcode/crackdetection/blob/main/src/inference.py): `src/inference.py`

### Inspection Tools

- [Video Inference](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/video_inference.py): `scripts/video_inference.py`
- [Image Explanations](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/explain_image.py): `scripts/explain_image.py`
- [Attention Masks](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/segment_cracks.py): `scripts/segment_cracks.py`
- [Segmenter Training](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/train_segmentation.py): `scripts/train_segmentation.py`
- [U-Net Architecture](https://github.com/witchcraftcode/crackdetection/blob/main/src/segmentation.py): `src/segmentation.py`
- [Drone Simulation](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/drone_inspection_sim.py): `scripts/drone_inspection_sim.py`

### Evaluation and Deployment

- [Metrics Evaluation](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/evaluate_metrics.py): `scripts/evaluate_metrics.py`
- [Architecture Benchmark](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/benchmark_architectures.py): `scripts/benchmark_architectures.py`
- [Edge Model Export](https://github.com/witchcraftcode/crackdetection/blob/main/scripts/export_edge_model.py): `scripts/export_edge_model.py`

### Other components

- **Labeled Images**
- **API Client**
- **Image User**

## Connections

- Labeled Images → Classifier Training: trains on (evidence: `README.md`)
- Classifier Training → Classifier Architectures: selects architecture (evidence: `scripts/train_classifier.py`)
- Classifier Training → Trained Classifier: saves model (evidence: `scripts/train_classifier.py`)
- API Client → Prediction API: uploads image (evidence: `README.md`)
- Image User → Image Inference: requests prediction (evidence: `README.md`)
- Prediction API → Cached Model Helper: calls prediction (evidence: `app.py`)
- Cached Model Helper → Image Inference: loads and predicts (evidence: `model.py`)
- Trained Classifier → Cached Model Helper: loaded by (evidence: `model.py`)
- Trained Classifier → Video Inference: loads for frames (evidence: `scripts/video_inference.py`)
- Video Inference → Image Inference: loads model (evidence: `scripts/video_inference.py`)
- Trained Classifier → Image Explanations: explained by (evidence: `README.md`)
- Image Explanations → Image Inference: loads and preprocesses (evidence: `scripts/explain_image.py`)
- Trained Classifier → Attention Masks: generates attention mask (evidence: `README.md`)
- Attention Masks → Image Explanations: uses Grad-CAM (evidence: `scripts/segment_cracks.py`)
- Attention Masks → Image Inference: loads and preprocesses (evidence: `scripts/segment_cracks.py`)
- Labeled Images → Segmenter Training: provides paired images and masks (evidence: `README.md`)
- Segmenter Training → U-Net Architecture: builds U-Net (evidence: `scripts/train_segmentation.py`)
- Trained Classifier → Drone Simulation: used for inspection (evidence: `README.md`)
- Drone Simulation → Image Inference: uses prediction (evidence: `scripts/drone_inspection_sim.py`)
- Trained Classifier → Metrics Evaluation: evaluated by (evidence: `README.md`)
- Metrics Evaluation → Image Inference: uses preprocessing (evidence: `scripts/evaluate_metrics.py`)
- Classifier Architectures → Architecture Benchmark: benchmarked by (evidence: `scripts/benchmark_architectures.py`)
- Trained Classifier → Edge Model Export: exports for edge (evidence: `README.md`)
