# spytensor/plants_disease_detection architecture

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

- Interactive diagram: https://gitdiagram.com/spytensor/plants_disease_detection
- Repository: https://github.com/spytensor/plants_disease_detection

## Overview

This repository is a PyTorch baseline for classifying crop-disease images. The workflow is: organize annotated images into class folders, load and augment training samples, split them into training and validation sets, train and evaluate a ResNet50 classifier, save the best checkpoint, then predict test images and write a submission JSON. Optional offline augmentation is separate from the main training path. The README documents CPU/GPU execution, AMP, and selectable focal loss; the graph follows the sampled runtime code and documented capabilities.

Main entry points: [`main.py`](https://github.com/spytensor/plants_disease_detection/blob/master/main.py) (Train and test), [`move.py`](https://github.com/spytensor/plants_disease_detection/blob/master/move.py) (Class organizer), [`data/train`](https://github.com/spytensor/plants_disease_detection/tree/master/data/train) (Class folders), [`dataset/dataloader.py`](https://github.com/spytensor/plants_disease_detection/blob/master/dataset/dataloader.py) (Dataset loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_raw["Raw images"]
  node_annotations["Train annotations"]
  node_organizer["Class organizer<br/>[move.py]"]
  node_trainset["Class folders"]
  node_testset["Test images"]
  node_offline_aug["Offline augmentation<br/>[data_aug.py]"]
end

subgraph group_learn["Model training"]
  node_loader["Dataset loader<br/>[dataloader.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_pipeline["Train and test<br/>[main.py]"]
  node_network["ResNet50 classifier<br/>[model.py]"]
  node_metrics["Loss and metrics<br/>[utils.py]"]
end

subgraph group_predict["Evaluation and prediction"]
  node_submission["Prediction JSON"]
end

subgraph group_state["Runtime state"]
  node_checkpoint["Model checkpoints"]
  node_logs["Training logs"]
end

node_user(("Dataset operator"))

node_user -->|"runs preparation"| node_organizer
node_annotations -->|"provides labels"| node_organizer
node_raw -->|"provides images"| node_organizer
node_organizer -->|"copies by class"| node_trainset
node_user -.->|"runs optionally"| node_offline_aug
node_trainset -.->|"reads images"| node_offline_aug
node_offline_aug -.->|"writes variants"| node_trainset
node_user -->|"starts training"| node_pipeline
node_pipeline -->|"reads settings"| node_config
node_pipeline -->|"loads samples"| node_loader
node_loader -->|"reads images"| node_trainset
node_loader -->|"reads images"| node_testset
node_pipeline -->|"creates and runs"| node_network
node_pipeline -->|"uses loss and metrics"| node_metrics
node_pipeline -->|"saves and reloads"| node_checkpoint
node_pipeline -->|"writes training log"| node_logs
node_pipeline -->|"writes predictions"| node_submission

click node_raw "https://github.com/spytensor/plants_disease_detection/tree/master/data/temp/images"
click node_annotations "https://github.com/spytensor/plants_disease_detection/tree/master/data/temp/labels"
click node_organizer "https://github.com/spytensor/plants_disease_detection/blob/master/move.py"
click node_trainset "https://github.com/spytensor/plants_disease_detection/tree/master/data/train"
click node_testset "https://github.com/spytensor/plants_disease_detection/tree/master/data/test"
click node_offline_aug "https://github.com/spytensor/plants_disease_detection/blob/master/data_aug.py"
click node_loader "https://github.com/spytensor/plants_disease_detection/blob/master/dataset/dataloader.py"
click node_config "https://github.com/spytensor/plants_disease_detection/blob/master/config.py"
click node_pipeline "https://github.com/spytensor/plants_disease_detection/blob/master/main.py"
click node_network "https://github.com/spytensor/plants_disease_detection/blob/master/models/model.py"
click node_metrics "https://github.com/spytensor/plants_disease_detection/blob/master/utils.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_raw,node_annotations,node_organizer,node_trainset,node_testset,node_offline_aug toneBlue
class node_loader,node_config,node_pipeline,node_network,node_metrics toneAmber
class node_submission toneMint
class node_checkpoint,node_logs toneRose
class node_user toneIndigo
```

## Components

### Data preparation

- [Raw images](https://github.com/spytensor/plants_disease_detection/tree/master/data/temp/images): `data/temp/images`
- [Train annotations](https://github.com/spytensor/plants_disease_detection/tree/master/data/temp/labels): `data/temp/labels`
- [Class organizer](https://github.com/spytensor/plants_disease_detection/blob/master/move.py): `move.py`
- [Class folders](https://github.com/spytensor/plants_disease_detection/tree/master/data/train): `data/train`
- [Test images](https://github.com/spytensor/plants_disease_detection/tree/master/data/test): `data/test`
- [Offline augmentation](https://github.com/spytensor/plants_disease_detection/blob/master/data_aug.py): `data_aug.py`

### Model training

- [Dataset loader](https://github.com/spytensor/plants_disease_detection/blob/master/dataset/dataloader.py): `dataset/dataloader.py`
- [Runtime configuration](https://github.com/spytensor/plants_disease_detection/blob/master/config.py): `config.py`
- [Train and test](https://github.com/spytensor/plants_disease_detection/blob/master/main.py): `main.py`
- [ResNet50 classifier](https://github.com/spytensor/plants_disease_detection/blob/master/models/model.py): `models/model.py`
- [Loss and metrics](https://github.com/spytensor/plants_disease_detection/blob/master/utils.py): `utils.py`

### Evaluation and prediction

- **Prediction JSON**

### Runtime state

- **Model checkpoints**
- **Training logs**

### Other components

- **Dataset operator**

## Connections

- Dataset operator → Class organizer: runs preparation
- Train annotations → Class organizer: provides labels
- Raw images → Class organizer: provides images
- Class organizer → Class folders: copies by class
- Dataset operator → Offline augmentation: runs optionally
- Class folders → Offline augmentation: reads images
- Offline augmentation → Class folders: writes variants
- Dataset operator → Train and test: starts training
- Train and test → Runtime configuration: reads settings
- Train and test → Dataset loader: loads samples
- Dataset loader → Class folders: reads images
- Dataset loader → Test images: reads images
- Train and test → ResNet50 classifier: creates and runs
- Train and test → Loss and metrics: uses loss and metrics
- Train and test → Model checkpoints: saves and reloads
- Train and test → Training logs: writes training log
- Train and test → Prediction JSON: writes predictions
