# brookww/papercnn architecture

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

- Interactive diagram: https://gitdiagram.com/brookww/papercnn
- Repository: https://github.com/brookww/papercnn

## Overview

PaperCNN classifies research fields from paper first-page images. Users either supply an image and load a checkpoint for a prediction, or provide dataset CSVs and images to check the data, train and validate a model, then evaluate a saved checkpoint on a split. The graph separates data preparation, the classifier, training, and prediction/evaluation. Source excerpts show the main calls; README statements support documented capabilities not fully visible in the excerpts.

Main entry points: [`train.py`](https://github.com/brookww/papercnn/blob/main/train.py) (Training loop), [`predict.py`](https://github.com/brookww/papercnn/blob/main/predict.py) (Split evaluation), [`data.py`](https://github.com/brookww/papercnn/blob/main/data.py) (Data loaders), [`model.py`](https://github.com/brookww/papercnn/blob/main/model.py) (PaperCNN)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_config["Defaults<br/>[config.py]"]
  node_manifest["CSV validation<br/>[data.py]"]
  node_split["Train/val split<br/>[data.py]"]
  node_image["Image preprocessing<br/>[data.py]"]
  node_loaders["Data loaders<br/>[data.py]"]
  node_integrity["Data checks<br/>[check.py]"]
end

subgraph group_model["Classifier"]
  node_cnn["PaperCNN<br/>[model.py]"]
  node_batch["Batch update<br/>[model.py]"]
  node_modelcheck["Model checks<br/>[check.py]"]
end

subgraph group_training["Training"]
  node_training["Training loop<br/>[train.py]"]
  node_metrics["Split metrics<br/>[train.py]"]
  node_checkpoint["Saved checkpoint<br/>[train.py]"]
end

subgraph group_inference["Prediction and evaluation"]
  node_single["Single-image prediction<br/>[predict.py]"]
  node_split_eval["Split evaluation<br/>[predict.py]"]
end

node_user(("User"))
node_dataset[("Dataset files")]

node_user -->|"starts training"| node_training
node_user -->|"requests prediction"| node_single
node_user -->|"requests evaluation"| node_split_eval
node_dataset -->|"provides CSVs"| node_manifest
node_dataset -->|"provides images"| node_image
node_manifest -->|"supplies rows"| node_split
node_split -->|"builds datasets"| node_loaders
node_image -->|"loads samples"| node_loaders
node_config -->|"sets defaults"| node_training
node_config -->|"sets image size"| node_loaders
node_loaders -->|"supplies batches"| node_training
node_training -->|"initializes model"| node_cnn
node_training -->|"updates batches"| node_batch
node_batch -->|"runs forward pass"| node_cnn
node_training -->|"evaluates validation"| node_metrics
node_metrics -->|"runs inference"| node_cnn
node_training -->|"saves best model"| node_checkpoint
node_training -->|"runs checks"| node_modelcheck
node_training -.->|"supports data checks"| node_integrity
node_single -->|"loads model"| node_checkpoint
node_single -->|"preprocesses image"| node_image
node_single -->|"classifies image"| node_cnn
node_split_eval -->|"loads model and split"| node_checkpoint
node_split_eval -->|"reads test CSV"| node_manifest
node_split_eval -->|"builds evaluation loader"| node_loaders
node_split_eval -->|"computes metrics"| node_metrics

click node_config "https://github.com/brookww/papercnn/blob/main/config.py"
click node_manifest "https://github.com/brookww/papercnn/blob/main/data.py"
click node_split "https://github.com/brookww/papercnn/blob/main/data.py"
click node_image "https://github.com/brookww/papercnn/blob/main/data.py"
click node_loaders "https://github.com/brookww/papercnn/blob/main/data.py"
click node_cnn "https://github.com/brookww/papercnn/blob/main/model.py"
click node_batch "https://github.com/brookww/papercnn/blob/main/model.py"
click node_integrity "https://github.com/brookww/papercnn/blob/main/check.py"
click node_modelcheck "https://github.com/brookww/papercnn/blob/main/check.py"
click node_training "https://github.com/brookww/papercnn/blob/main/train.py"
click node_metrics "https://github.com/brookww/papercnn/blob/main/train.py"
click node_checkpoint "https://github.com/brookww/papercnn/blob/main/train.py"
click node_single "https://github.com/brookww/papercnn/blob/main/predict.py"
click node_split_eval "https://github.com/brookww/papercnn/blob/main/predict.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_config,node_manifest,node_split,node_image,node_loaders,node_integrity,node_user toneBlue
class node_cnn,node_batch,node_modelcheck,node_dataset toneAmber
class node_training,node_metrics,node_checkpoint toneMint
class node_single,node_split_eval toneRose
```

## Components

### Data preparation

- [Defaults](https://github.com/brookww/papercnn/blob/main/config.py): `config.py`
- [CSV validation](https://github.com/brookww/papercnn/blob/main/data.py): `data.py`
- [Train/val split](https://github.com/brookww/papercnn/blob/main/data.py): `data.py`
- [Image preprocessing](https://github.com/brookww/papercnn/blob/main/data.py): `data.py`
- [Data loaders](https://github.com/brookww/papercnn/blob/main/data.py): `data.py`
- [Data checks](https://github.com/brookww/papercnn/blob/main/check.py): `check.py`

### Classifier

- [PaperCNN](https://github.com/brookww/papercnn/blob/main/model.py): `model.py`
- [Batch update](https://github.com/brookww/papercnn/blob/main/model.py): `model.py`
- [Model checks](https://github.com/brookww/papercnn/blob/main/check.py): `check.py`

### Training

- [Training loop](https://github.com/brookww/papercnn/blob/main/train.py): `train.py`
- [Split metrics](https://github.com/brookww/papercnn/blob/main/train.py): `train.py`
- [Saved checkpoint](https://github.com/brookww/papercnn/blob/main/train.py): `train.py`

### Prediction and evaluation

- [Single-image prediction](https://github.com/brookww/papercnn/blob/main/predict.py): `predict.py`
- [Split evaluation](https://github.com/brookww/papercnn/blob/main/predict.py): `predict.py`

### Other components

- **User**
- **Dataset files**

## Connections

- User → Training loop: starts training (evidence: `README.md`)
- User → Single-image prediction: requests prediction (evidence: `README.md`)
- User → Split evaluation: requests evaluation (evidence: `README.md`)
- Dataset files → CSV validation: provides CSVs (evidence: `data.py`)
- Dataset files → Image preprocessing: provides images (evidence: `data.py`)
- CSV validation → Train/val split: supplies rows (evidence: `data.py`)
- Train/val split → Data loaders: builds datasets (evidence: `data.py`)
- Image preprocessing → Data loaders: loads samples (evidence: `data.py`)
- Defaults → Training loop: sets defaults (evidence: `train.py`)
- Defaults → Data loaders: sets image size (evidence: `train.py`)
- Data loaders → Training loop: supplies batches (evidence: `train.py`)
- Training loop → PaperCNN: initializes model (evidence: `train.py`)
- Training loop → Batch update: updates batches (evidence: `train.py`)
- Batch update → PaperCNN: runs forward pass (evidence: `model.py`)
- Training loop → Split metrics: evaluates validation (evidence: `train.py`)
- Split metrics → PaperCNN: runs inference (evidence: `train.py`)
- Training loop → Saved checkpoint: saves best model (evidence: `train.py`)
- Training loop → Model checks: runs checks (evidence: `train.py`)
- Training loop → Data checks: supports data checks (evidence: `README.md`)
- Single-image prediction → Saved checkpoint: loads model (evidence: `predict.py`)
- Single-image prediction → Image preprocessing: preprocesses image (evidence: `predict.py`)
- Single-image prediction → PaperCNN: classifies image (evidence: `predict.py`)
- Split evaluation → Saved checkpoint: loads model and split (evidence: `predict.py`)
- Split evaluation → CSV validation: reads test CSV (evidence: `predict.py`)
- Split evaluation → Data loaders: builds evaluation loader (evidence: `predict.py`)
- Split evaluation → Split metrics: computes metrics (evidence: `predict.py`)
