# nyukat/breast_cancer_classifier architecture

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

- Interactive diagram: https://gitdiagram.com/nyukat/breast_cancer_classifier
- Repository: https://github.com/nyukat/breast_cancer_classifier

## Overview

This repository implements pretrained breast-cancer classifiers for screening mammograms. The primary workflow accepts an exam’s four standard views, crops and centers the images, optionally generates benign/malignant heatmaps, then predicts benign and malignant probabilities for each breast. It also supports single-image inference and image-only or image-plus-heatmap models, with a separate TensorFlow image-wise implementation. The README documents the user-facing stages; internal links below rely on indexed source references, so unsampled implementation details are not inferred.

Main entry points: [`src/optimal_centers/get_optimal_centers.py`](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/optimal_centers/get_optimal_centers.py) (Optimal centers), [`src/heatmaps/run_producer.py`](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer.py) (Exam heatmaps), [`src/cropping/crop_mammogram.py`](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/cropping/crop_mammogram.py) (Mammogram cropping), [`src/data_loading/loading.py`](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/data_loading/loading.py) (Image loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preprocess["Image preprocessing"]
  node_crop["Mammogram cropping<br/>[crop_mammogram.py]"]
  node_crop_single["Single-image crop<br/>[crop_single.py]"]
  node_centers["Optimal centers"]
  node_center_calc["Center calculation"]
end

subgraph group_heatmaps["Heatmap generation"]
  node_heatmap_run["Exam heatmaps<br/>[run_producer.py]"]
  node_heatmap_single["Single-image heatmaps"]
  node_heatmap_tf["TensorFlow heatmaps"]
  node_patch_model["Patch classifier<br/>[models.py]"]
end

subgraph group_classification["Cancer classification"]
  node_classifier_run["Exam classifier<br/>[run_model.py]"]
  node_classifier_single["Single-image classifier"]
  node_classifier_tf["TensorFlow classifier"]
  node_models["PyTorch models<br/>[models.py]"]
  node_layers["PyTorch layers<br/>[layers.py]"]
  node_models_tf["TensorFlow models<br/>[models_tf.py]"]
  node_layers_tf["TensorFlow layers<br/>[layers_tf.py]"]
end

subgraph group_shared["Shared data and utilities"]
  node_loading["Image loading<br/>[loading.py]"]
  node_augment["Crop augmentation<br/>[augmentations.py]"]
  node_constants["Views and labels<br/>[constants.py]"]
  node_data_handling["Exam metadata<br/>[data_handling.py]"]
  node_pickling["Exam-list storage<br/>[pickling.py]"]
  node_image_read["Image readers<br/>[reading_images.py]"]
  node_image_save["Image writers<br/>[saving_images.py]"]
  node_tools["Batch utilities<br/>[tools.py]"]
end

node_user(("Research user"))
node_predictions["Breast probabilities"]

node_user -->|"starts preprocessing"| node_crop
node_crop -->|"cropped images"| node_centers
node_centers -->|"centered views"| node_heatmap_run
node_heatmap_run -->|"heatmaps"| node_classifier_run
node_classifier_run -->|"predicts probabilities"| node_predictions
node_user -->|"runs single image"| node_crop_single
node_crop_single -->|"extracts centers"| node_centers
node_centers -->|"centered image"| node_heatmap_single
node_heatmap_single -->|"heatmaps"| node_classifier_single
node_classifier_single -->|"returns probabilities"| node_predictions
node_user -.->|"selects TensorFlow"| node_heatmap_tf
node_heatmap_run -->|"uses patch model"| node_patch_model
node_heatmap_run -->|"loads views"| node_loading
node_heatmap_run -->|"saves heatmaps"| node_image_save
node_heatmap_single -->|"reuses producer"| node_heatmap_run
node_heatmap_tf -->|"loads views"| node_loading
node_heatmap_tf -->|"saves heatmaps"| node_image_save
node_classifier_run -->|"loads inputs"| node_loading
node_classifier_run -->|"loads classifier"| node_models
node_classifier_single -->|"loads image"| node_loading
node_classifier_single -->|"uses classifier"| node_models
node_classifier_tf -->|"uses classifier"| node_models_tf
node_loading -->|"augments crops"| node_augment
node_models -->|"uses layers"| node_layers
node_models_tf -->|"uses layers"| node_layers_tf
node_centers -->|"calculates centers"| node_center_calc
node_centers -->|"unpacks exams"| node_data_handling
node_centers -->|"reads images"| node_image_read
node_centers -->|"stores metadata"| node_pickling
node_crop -->|"unpacks exams"| node_data_handling
node_crop -->|"reads exam list"| node_pickling
node_crop -->|"reads images"| node_image_read
node_crop -->|"writes crops"| node_image_save
node_classifier_run -->|"batches inference"| node_tools
node_heatmap_run -->|"batches patches"| node_tools
node_constants -->|"defines view sizes"| node_loading
node_constants -->|"defines view keys"| node_data_handling

click node_crop "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/cropping/crop_mammogram.py"
click node_crop_single "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/cropping/crop_single.py"
click node_centers "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/optimal_centers/get_optimal_centers.py"
click node_center_calc "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/optimal_centers/calc_optimal_centers.py"
click node_loading "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/data_loading/loading.py"
click node_augment "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/data_loading/augmentations.py"
click node_heatmap_run "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer.py"
click node_heatmap_single "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer_single.py"
click node_heatmap_tf "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer_single_tf.py"
click node_patch_model "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/models.py"
click node_classifier_run "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/run_model.py"
click node_classifier_single "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/run_model_single.py"
click node_classifier_tf "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/run_model_single_tf.py"
click node_models "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/models.py"
click node_layers "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/layers.py"
click node_models_tf "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/models_tf.py"
click node_layers_tf "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/layers_tf.py"
click node_constants "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/constants.py"
click node_data_handling "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/data_handling.py"
click node_pickling "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/pickling.py"
click node_image_read "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/reading_images.py"
click node_image_save "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/saving_images.py"
click node_tools "https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/tools.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_crop,node_crop_single,node_centers,node_center_calc,node_user toneBlue
class node_heatmap_run,node_heatmap_single,node_heatmap_tf,node_patch_model toneAmber
class node_classifier_run,node_classifier_single,node_classifier_tf,node_models,node_layers,node_models_tf,node_layers_tf toneMint
class node_loading,node_augment,node_constants,node_data_handling,node_pickling,node_image_read,node_image_save,node_tools toneRose
class node_predictions toneIndigo
```

## Components

### Image preprocessing

- [Mammogram cropping](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/cropping/crop_mammogram.py): `src/cropping/crop_mammogram.py`
- [Single-image crop](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/cropping/crop_single.py): `src/cropping/crop_single.py`
- [Optimal centers](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/optimal_centers/get_optimal_centers.py): `src/optimal_centers/get_optimal_centers.py`
- [Center calculation](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/optimal_centers/calc_optimal_centers.py): `src/optimal_centers/calc_optimal_centers.py`

### Heatmap generation

- [Exam heatmaps](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer.py): `src/heatmaps/run_producer.py`
- [Single-image heatmaps](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer_single.py): `src/heatmaps/run_producer_single.py`
- [TensorFlow heatmaps](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/run_producer_single_tf.py): `src/heatmaps/run_producer_single_tf.py`
- [Patch classifier](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/heatmaps/models.py): `src/heatmaps/models.py`

### Cancer classification

- [Exam classifier](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/run_model.py): `src/modeling/run_model.py`
- [Single-image classifier](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/run_model_single.py): `src/modeling/run_model_single.py`
- [TensorFlow classifier](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/run_model_single_tf.py): `src/modeling/run_model_single_tf.py`
- [PyTorch models](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/models.py): `src/modeling/models.py`
- [PyTorch layers](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/layers.py): `src/modeling/layers.py`
- [TensorFlow models](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/models_tf.py): `src/modeling/models_tf.py`
- [TensorFlow layers](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/modeling/layers_tf.py): `src/modeling/layers_tf.py`

### Shared data and utilities

- [Image loading](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/data_loading/loading.py): `src/data_loading/loading.py`
- [Crop augmentation](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/data_loading/augmentations.py): `src/data_loading/augmentations.py`
- [Views and labels](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/constants.py): `src/constants.py`
- [Exam metadata](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/data_handling.py): `src/utilities/data_handling.py`
- [Exam-list storage](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/pickling.py): `src/utilities/pickling.py`
- [Image readers](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/reading_images.py): `src/utilities/reading_images.py`
- [Image writers](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/saving_images.py): `src/utilities/saving_images.py`
- [Batch utilities](https://github.com/nyukat/breast_cancer_classifier/blob/master/src/utilities/tools.py): `src/utilities/tools.py`

### Other components

- **Research user**
- **Breast probabilities**

## Connections

- Research user → Mammogram cropping: starts preprocessing (evidence: `README.md`)
- Mammogram cropping → Optimal centers: cropped images (evidence: `README.md`)
- Optimal centers → Exam heatmaps: centered views (evidence: `README.md`)
- Exam heatmaps → Exam classifier: heatmaps (evidence: `README.md`)
- Exam classifier → Breast probabilities: predicts probabilities (evidence: `README.md`)
- Research user → Single-image crop: runs single image (evidence: `README.md`)
- Single-image crop → Optimal centers: extracts centers (evidence: `README.md`)
- Optimal centers → Single-image heatmaps: centered image (evidence: `README.md`)
- Single-image heatmaps → Single-image classifier: heatmaps (evidence: `README.md`)
- Single-image classifier → Breast probabilities: returns probabilities (evidence: `README.md`)
- Research user → TensorFlow heatmaps: selects TensorFlow (evidence: `README.md`)
- Exam heatmaps → Patch classifier: uses patch model (evidence: `src/heatmaps/run_producer.py`)
- Exam heatmaps → Image loading: loads views (evidence: `src/heatmaps/run_producer.py`)
- Exam heatmaps → Image writers: saves heatmaps (evidence: `src/heatmaps/run_producer.py`)
- Single-image heatmaps → Exam heatmaps: reuses producer (evidence: `src/heatmaps/run_producer_single.py`)
- TensorFlow heatmaps → Image loading: loads views (evidence: `src/heatmaps/run_producer_single_tf.py`)
- TensorFlow heatmaps → Image writers: saves heatmaps (evidence: `src/heatmaps/run_producer_single_tf.py`)
- Exam classifier → Image loading: loads inputs (evidence: `src/modeling/run_model.py`)
- Exam classifier → PyTorch models: loads classifier (evidence: `src/modeling/run_model.py`)
- Single-image classifier → Image loading: loads image (evidence: `src/modeling/run_model_single.py`)
- Single-image classifier → PyTorch models: uses classifier (evidence: `src/modeling/run_model_single.py`)
- TensorFlow classifier → TensorFlow models: uses classifier (evidence: `src/modeling/run_model_single_tf.py`)
- Image loading → Crop augmentation: augments crops (evidence: `src/data_loading/loading.py`)
- PyTorch models → PyTorch layers: uses layers (evidence: `src/modeling/models.py`)
- TensorFlow models → TensorFlow layers: uses layers (evidence: `src/modeling/models_tf.py`)
- Optimal centers → Center calculation: calculates centers (evidence: `src/optimal_centers/get_optimal_centers.py`)
- Optimal centers → Exam metadata: unpacks exams (evidence: `src/optimal_centers/get_optimal_centers.py`)
- Optimal centers → Image readers: reads images (evidence: `src/optimal_centers/get_optimal_centers.py`)
- Optimal centers → Exam-list storage: stores metadata (evidence: `src/optimal_centers/get_optimal_centers.py`)
- Mammogram cropping → Exam metadata: unpacks exams (evidence: `src/cropping/crop_mammogram.py`)
- Mammogram cropping → Exam-list storage: reads exam list (evidence: `src/cropping/crop_mammogram.py`)
- Mammogram cropping → Image readers: reads images (evidence: `src/cropping/crop_mammogram.py`)
- Mammogram cropping → Image writers: writes crops (evidence: `src/cropping/crop_mammogram.py`)
- Exam classifier → Batch utilities: batches inference (evidence: `src/modeling/run_model.py`)
- Exam heatmaps → Batch utilities: batches patches (evidence: `src/heatmaps/run_producer.py`)
- Views and labels → Image loading: defines view sizes (evidence: `src/data_loading/loading.py`)
- Views and labels → Exam metadata: defines view keys (evidence: `src/utilities/data_handling.py`)
