# lalbee/structural-damage-recognition architecture

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

- Interactive diagram: https://gitdiagram.com/lalbee/structural-damage-recognition
- Repository: https://github.com/lalbee/structural-damage-recognition

## Overview

This repository is a structural-image damage classifier, with a Gradio upload demo and a command-line prediction tool. Its main workflow prepares and balances image data, trains and evaluates transfer-learning models, then classifies images as Damaged or Undamaged with confidence scores. The README documents model comparison and evaluation artifacts. Training details come from a partial source excerpt, so the graph does not infer unshown internal training calls.

Main entry points: [`src/train.py`](https://github.com/lalbee/structural-damage-recognition/blob/main/src/train.py) (Transfer-learning trainer), [`app.py`](https://github.com/lalbee/structural-damage-recognition/blob/main/app.py) (Gradio demo), [`src/predict.py`](https://github.com/lalbee/structural-damage-recognition/blob/main/src/predict.py) (CLI prediction), [`src/prepare_data.py`](https://github.com/lalbee/structural-damage-recognition/blob/main/src/prepare_data.py) (Array preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_prep["Array preparation<br/>[prepare_data.py]"]
  node_subset["Balanced subset<br/>[create_subset.py]"]
  node_arrays[("Prepared arrays")]
end

subgraph group_model["Model training"]
  node_trainer["Transfer-learning trainer<br/>[train.py]"]
  node_weights["Model checkpoints"]
  node_evaluation["Test evaluation<br/>[train.py]"]
  node_artifacts["Metrics and errors"]
end

subgraph group_serve["Prediction interfaces"]
  node_cli["CLI prediction<br/>[predict.py]"]
  node_demo["Gradio demo<br/>[app.py]"]
end

node_dataset[("PEER image data")]
node_cli_user(("CLI user"))
node_demo_user(("Demo user"))
node_drive[("Google Drive")]

node_dataset -->|"loads arrays"| node_prep
node_prep -->|"writes arrays"| node_arrays
node_arrays -->|"loads training data"| node_subset
node_subset -->|"writes subset"| node_arrays
node_arrays -->|"trains on"| node_trainer
node_trainer -->|"saves checkpoint"| node_weights
node_trainer -->|"evaluates model"| node_evaluation
node_evaluation -->|"writes metrics"| node_artifacts
node_cli_user -->|"requests prediction"| node_cli
node_weights -->|"loads checkpoint"| node_cli
node_cli -->|"returns class and confidence"| node_cli_user
node_demo_user -->|"uploads image"| node_demo
node_demo -->|"downloads checkpoint"| node_drive
node_demo -->|"displays prediction"| node_demo_user

click node_prep "https://github.com/lalbee/structural-damage-recognition/blob/main/src/prepare_data.py"
click node_subset "https://github.com/lalbee/structural-damage-recognition/blob/main/src/create_subset.py"
click node_trainer "https://github.com/lalbee/structural-damage-recognition/blob/main/src/train.py"
click node_evaluation "https://github.com/lalbee/structural-damage-recognition/blob/main/src/train.py"
click node_artifacts "https://github.com/lalbee/structural-damage-recognition/tree/main/results"
click node_cli "https://github.com/lalbee/structural-damage-recognition/blob/main/src/predict.py"
click node_demo "https://github.com/lalbee/structural-damage-recognition/blob/main/app.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_prep,node_subset,node_arrays,node_cli_user,node_demo_user toneBlue
class node_trainer,node_weights,node_evaluation,node_artifacts,node_dataset,node_drive toneAmber
class node_cli,node_demo toneMint
```

## Components

### Data preparation

- [Array preparation](https://github.com/lalbee/structural-damage-recognition/blob/main/src/prepare_data.py): `src/prepare_data.py`
- [Balanced subset](https://github.com/lalbee/structural-damage-recognition/blob/main/src/create_subset.py): `src/create_subset.py`
- **Prepared arrays**

### Model training

- [Transfer-learning trainer](https://github.com/lalbee/structural-damage-recognition/blob/main/src/train.py): `src/train.py`
- **Model checkpoints**
- [Test evaluation](https://github.com/lalbee/structural-damage-recognition/blob/main/src/train.py): `src/train.py`
- [Metrics and errors](https://github.com/lalbee/structural-damage-recognition/tree/main/results): `results`

### Prediction interfaces

- [CLI prediction](https://github.com/lalbee/structural-damage-recognition/blob/main/src/predict.py): `src/predict.py`
- [Gradio demo](https://github.com/lalbee/structural-damage-recognition/blob/main/app.py): `app.py`

### Other components

- **PEER image data**
- **CLI user**
- **Demo user**
- **Google Drive**

## Connections

- PEER image data → Array preparation: loads arrays (evidence: `src/prepare_data.py`)
- Array preparation → Prepared arrays: writes arrays (evidence: `src/prepare_data.py`)
- Prepared arrays → Balanced subset: loads training data (evidence: `src/create_subset.py`)
- Balanced subset → Prepared arrays: writes subset (evidence: `src/create_subset.py`)
- Prepared arrays → Transfer-learning trainer: trains on (evidence: `README.md`)
- Transfer-learning trainer → Model checkpoints: saves checkpoint (evidence: `README.md`)
- Transfer-learning trainer → Test evaluation: evaluates model (evidence: `README.md`)
- Test evaluation → Metrics and errors: writes metrics (evidence: `README.md`)
- CLI user → CLI prediction: requests prediction (evidence: `README.md`)
- Model checkpoints → CLI prediction: loads checkpoint (evidence: `src/predict.py`)
- CLI prediction → CLI user: returns class and confidence (evidence: `src/predict.py`)
- Demo user → Gradio demo: uploads image (evidence: `app.py`)
- Gradio demo → Google Drive: downloads checkpoint (evidence: `app.py`)
- Gradio demo → Demo user: displays prediction (evidence: `app.py`)
