# badivana/chest-x-ray-classification architecture

> Architecture diagram of the GitHub repository badivana/chest-x-ray-classification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/badivana/chest-x-ray-classification
- Repository: https://github.com/badivana/chest-x-ray-classification

## Overview

This repository is a chest X-ray classifier project: its documented workflow trains and evaluates a model, then classifies new images; Grad-CAM can explain a prediction with a heatmap. The README describes preprocessing, augmentation, and ResNet50 transfer learning, while `scr/gradcam.py` defines a custom CNN for inference, so those model descriptions may reflect different or outdated implementations. Training notebook internals were not sampled; its relationships are shown only where the README documents them.

Main entry points: [`scr/gradcam.py`](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py) (Grad-CAM CLI), [`train_model.ipynb`](https://github.com/badivana/chest-x-ray-classification/blob/main/train_model.ipynb) (Train and evaluate), [`best_model.pth`](https://github.com/badivana/chest-x-ray-classification/blob/main/best_model.pth) (Trained weights), [`dataset`](https://github.com/badivana/chest-x-ray-classification/tree/main/dataset) (X-ray dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model Development"]
  node_training["Train and evaluate<br/>[train_model.ipynb]"]
  node_dataset[("X-ray dataset")]
  node_checkpoint["Trained weights<br/>[best_model.pth]"]
end

subgraph group_inference["Prediction"]
  node_cli["Grad-CAM CLI<br/>[gradcam.py]"]
  node_cnn["CNN model<br/>[gradcam.py]"]
  node_preprocess["Image preprocessing<br/>[gradcam.py]"]
  node_prediction["Class prediction<br/>[gradcam.py]"]
end

subgraph group_explain["Explainability"]
  node_gradcam["Grad-CAM heatmap<br/>[gradcam.py]"]
  node_overlay["Heatmap overlay<br/>[gradcam.py]"]
end

node_user(("Image user"))
node_image["X-ray image"]
node_result["Class and overlay"]

node_dataset -->|"trains on"| node_training
node_training -->|"produces weights"| node_checkpoint
node_user -->|"runs"| node_cli
node_image -->|"supplies image"| node_cli
node_cli -->|"loads weights"| node_cnn
node_checkpoint -->|"provides weights"| node_cnn
node_cli -->|"calls"| node_preprocess
node_preprocess -->|"returns tensor"| node_prediction
node_cli -->|"runs explanation"| node_gradcam
node_gradcam -->|"queries"| node_cnn
node_cli -->|"creates overlay"| node_overlay
node_prediction -->|"reports class"| node_result
node_overlay -->|"saves image"| node_result

click node_training "https://github.com/badivana/chest-x-ray-classification/blob/main/train_model.ipynb"
click node_dataset "https://github.com/badivana/chest-x-ray-classification/tree/main/dataset"
click node_checkpoint "https://github.com/badivana/chest-x-ray-classification/blob/main/best_model.pth"
click node_cli "https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py"
click node_cnn "https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py"
click node_preprocess "https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py"
click node_prediction "https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py"
click node_gradcam "https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py"
click node_overlay "https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.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_training,node_dataset,node_checkpoint,node_user toneBlue
class node_cli,node_cnn,node_preprocess,node_prediction toneAmber
class node_gradcam,node_overlay toneMint
class node_image,node_result toneIndigo
```

## Components

### Model Development

- [Train and evaluate](https://github.com/badivana/chest-x-ray-classification/blob/main/train_model.ipynb): `train_model.ipynb`
- [X-ray dataset](https://github.com/badivana/chest-x-ray-classification/tree/main/dataset): `dataset`
- [Trained weights](https://github.com/badivana/chest-x-ray-classification/blob/main/best_model.pth): `best_model.pth`

### Prediction

- [Grad-CAM CLI](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py): `scr/gradcam.py`
- [CNN model](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py): `scr/gradcam.py`
- [Image preprocessing](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py): `scr/gradcam.py`
- [Class prediction](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py): `scr/gradcam.py`

### Explainability

- [Grad-CAM heatmap](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py): `scr/gradcam.py`
- [Heatmap overlay](https://github.com/badivana/chest-x-ray-classification/blob/main/scr/gradcam.py): `scr/gradcam.py`

### Other components

- **Image user**
- **X-ray image**
- **Class and overlay**

## Connections

- X-ray dataset → Train and evaluate: trains on (evidence: `README.md`)
- Train and evaluate → Trained weights: produces weights (evidence: `README.md`)
- Image user → Grad-CAM CLI: runs (evidence: `README.md`)
- X-ray image → Grad-CAM CLI: supplies image (evidence: `README.md`)
- Grad-CAM CLI → CNN model: loads weights (evidence: `scr/gradcam.py`)
- Trained weights → CNN model: provides weights (evidence: `scr/gradcam.py`)
- Grad-CAM CLI → Image preprocessing: calls (evidence: `scr/gradcam.py`)
- Image preprocessing → Class prediction: returns tensor (evidence: `scr/gradcam.py`)
- Grad-CAM CLI → Grad-CAM heatmap: runs explanation (evidence: `scr/gradcam.py`)
- Grad-CAM heatmap → CNN model: queries (evidence: `scr/gradcam.py`)
- Grad-CAM CLI → Heatmap overlay: creates overlay (evidence: `scr/gradcam.py`)
- Class prediction → Class and overlay: reports class (evidence: `scr/gradcam.py`)
- Heatmap overlay → Class and overlay: saves image (evidence: `scr/gradcam.py`)
