# arnoweng/chexnet architecture

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

- Interactive diagram: https://gitdiagram.com/arnoweng/chexnet
- Repository: https://github.com/arnoweng/chexnet

## Overview

##### Project type and purpose
- This is a machine-learning project (PyTorch-based) for classification and localization of thoracic diseases from chest X-ray images.
- Key purpose: train and evaluate a DenseNet-based CNN (CheXNet) on the NIH ChestX-ray14 dataset to output per-disease probabilities and heatmaps indicating pathology locations.

##### File structure
- Top level:
- ChestX-ray14/
– images/ (raw X-ray files)
– labels/ (train/val/test split lists)
- model.py (defines model, training, evaluation loops)
- read_data.py (data loading / preprocessing utilities)
- localization/ (generated likelihood maps / visualization outputs)
- model.pth.tar (pretrained or checkpoint weights)
- README.md (project description)
- Patterns: a single-service ML pipeline (data loader → model → results). No separate “frontend” or microservices.

##### README for additional insights
- Confirms dataset splits, model architecture (CheXNet / DenseNet121), training strategy (ten-crop augmentation), outputs (AUROC metrics, localization heatmaps).

##### Elements
- Clear labels for each component (e.g., “Data Loader”, “CheXNet Model”, “Localization Heatmap Generator”).

##### Detailed breakdown to capture essential architectural elements
1. Data Storage (ChestX-ray14/)
- Raw image files
2. Data Loading & Preprocessing
- read_data.py: parses labels, builds PyTorch Dataset
- DataLoader: batch loading, on-the-fly augmentation (e.g., ten-crop)
3. Model Component
- model.py: defines CheXNet architecture (DenseNet121 backbone)
- Training loop: loss computation, backprop, optimizer step
- Evaluation loop: compute AUROC per disease
4. Checkpoint Management
- Save best model to model.pth.tar
- Load pretrained weights if available
5. Localization Module
- After forward pass, generate likelihood map heatmaps
- Save PNGs under localization/
6. External Interfaces
- GPU / CUDA
- Python RT logs or console outputs for metrics

[ChestX-ray14/images + labels] → [Data Loader (read_data.py)] → [CheXNet Model (model.py) on GPU] → split outputs →
- [Metrics Calculator (AUROC)]
- [Localization Heatmap Generator → localization/]
↕
[Checkpoint Store (model.pth.tar)]

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Storage"
        DSImages["ChestX-ray14/images"]:::storage
        subgraph "Label Splits"
            TrainList["train_list.txt"]:::storage
            ValList["val_list.txt"]:::storage
            TestList["test_list.txt"]:::storage
        end
    end

    DataLoader["Data Loader (read_data.py)\n(PyTorch Dataset & Augmentation)"]:::compute
    Model["CheXNet Model (model.py)\n(DenseNet121 on GPU)"]:::compute
    Checkpoint["Checkpoint Store\n(model.pth.tar)"]:::storage
    Metrics["Metrics Calculator\n(AUROC)"]:::output
    Heatmap["Localization Heatmap Generator"]:::output
    Frameworks["PyTorch / CUDA"]:::framework

    DSImages --> DataLoader
    TrainList --> DataLoader
    ValList --> DataLoader
    TestList --> DataLoader
    DataLoader --> Model
    Frameworks --> Model
    Model --> Checkpoint
    Checkpoint --> Model
    Model --> Metrics
    Model --> Heatmap

    click DSImages "https://github.com/arnoweng/chexnet/tree/master/ChestX-ray14/images/"
    click TrainList "https://github.com/arnoweng/chexnet/blob/master/ChestX-ray14/labels/train_list.txt"
    click ValList "https://github.com/arnoweng/chexnet/blob/master/ChestX-ray14/labels/val_list.txt"
    click TestList "https://github.com/arnoweng/chexnet/blob/master/ChestX-ray14/labels/test_list.txt"
    click DataLoader "https://github.com/arnoweng/chexnet/blob/master/read_data.py"
    click Model "https://github.com/arnoweng/chexnet/blob/master/model.py"
    click Checkpoint "https://github.com/arnoweng/chexnet/blob/master/model.pth.tar"
    click Heatmap "https://github.com/arnoweng/chexnet/tree/master/localization/"

    classDef storage fill:#1f77b4,stroke:#000,color:#fff
    classDef compute fill:#2ca02c,stroke:#000,color:#fff
    classDef output fill:#ff7f0e,stroke:#000,color:#000
    classDef framework fill:#d62728,stroke:#000,color:#fff
```
