# psvedant/leafnet_mcmd_gradcam architecture

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

- Interactive diagram: https://gitdiagram.com/psvedant/leafnet_mcmd_gradcam
- Repository: https://github.com/psvedant/leafnet_mcmd_gradcam

## Overview

LeafNet-MCMD is a plant-leaf disease classification project: it prepares image datasets, trains a compact custom CNN, and produces evaluation, explainability, and error-audit outputs. Its separate FastAPI application accepts an uploaded image and returns a prediction with a Grad-CAM visualization. The main training and analysis relationships below follow the README pipeline; the app’s inference and heatmap steps are visible in its excerpt. Other model variants and experimental scripts are not expanded into separate runtime flows.

Main entry points: [`data`](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/data) (Train, val, test), [`outputs_novel`](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel) (Trained model), [`src/custom_cnn.py`](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/custom_cnn.py) (Train and checkpoint), [`src/evaluate_custom.py`](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/evaluate_custom.py) (Multiclass metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dataset preparation"]
  node_stage["Stage raw data<br/>[setup_folders.py]"]
  node_raw["Raw dataset"]
  node_split["Build splits<br/>[split_dataset.py]"]
  node_splits["Train, val, test"]
end

subgraph group_model["Model development"]
  node_architecture["Custom CNN blocks<br/>[custom_cnn.py]"]
  node_training["Train and checkpoint<br/>[custom_cnn.py]"]
  node_checkpoint["Trained model"]
end

subgraph group_analysis["Model analysis"]
  node_metrics["Multiclass metrics<br/>[evaluate_custom.py]"]
  node_metricoutputs["Reports and plots"]
  node_explain["Grad-CAM heatmaps<br/>[gradcam.py]"]
  node_heatmaps["Class heatmaps"]
  node_audit["Error audit<br/>[analyze_errors.py]"]
  node_erroroutputs["Error images and CSV"]
end

subgraph group_serving["Prediction API"]
  node_api["Prediction endpoint<br/>[app.py]"]
  node_inference["Class prediction<br/>[app.py]"]
  node_heatmapapi["Prediction heatmap<br/>[app.py]"]
end

node_archive["Plant disease images"]
node_user(("Image submitter"))

node_archive -->|"stages"| node_stage
node_stage -->|"writes"| node_raw
node_raw -->|"provides images"| node_split
node_split -->|"creates"| node_splits
node_splits -->|"trains on"| node_training
node_architecture -->|"builds model for"| node_training
node_training -->|"saves"| node_checkpoint
node_checkpoint -->|"evaluates"| node_metrics
node_splits -->|"supplies test data"| node_metrics
node_metrics -->|"writes"| node_metricoutputs
node_checkpoint -->|"explains predictions"| node_explain
node_splits -->|"supplies test images"| node_explain
node_explain -->|"writes"| node_heatmaps
node_checkpoint -->|"audits errors"| node_audit
node_splits -->|"supplies test images"| node_audit
node_audit -->|"writes"| node_erroroutputs
node_user -->|"uploads image"| node_api
node_api -->|"predicts"| node_inference
node_inference -->|"generates heatmap"| node_heatmapapi

click node_stage "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/setup_folders.py"
click node_raw "https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/data/raw"
click node_split "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/split_dataset.py"
click node_splits "https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/data"
click node_architecture "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/custom_cnn.py"
click node_training "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/custom_cnn.py"
click node_checkpoint "https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel"
click node_metrics "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/evaluate_custom.py"
click node_metricoutputs "https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel/evaluation"
click node_explain "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/gradcam.py"
click node_heatmaps "https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel/gradcam"
click node_audit "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/analyze_errors.py"
click node_erroroutputs "https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel/error_analysis"
click node_api "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/app.py"
click node_inference "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/app.py"
click node_heatmapapi "https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/app.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_stage,node_raw,node_split,node_splits toneBlue
class node_architecture,node_training,node_checkpoint toneAmber
class node_metrics,node_metricoutputs,node_explain,node_heatmaps,node_audit,node_erroroutputs toneMint
class node_api,node_inference,node_heatmapapi toneRose
class node_archive,node_user toneIndigo
```

## Components

### Dataset preparation

- [Stage raw data](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/setup_folders.py): `src/setup_folders.py`
- [Raw dataset](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/data/raw): `data/raw`
- [Build splits](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/split_dataset.py): `src/split_dataset.py`
- [Train, val, test](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/data): `data`

### Model development

- [Custom CNN blocks](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/custom_cnn.py): `src/custom_cnn.py`
- [Train and checkpoint](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/custom_cnn.py): `src/custom_cnn.py`
- [Trained model](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel): `outputs_novel`

### Model analysis

- [Multiclass metrics](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/evaluate_custom.py): `src/evaluate_custom.py`
- [Reports and plots](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel/evaluation): `outputs_novel/evaluation`
- [Grad-CAM heatmaps](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/gradcam.py): `src/gradcam.py`
- [Class heatmaps](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel/gradcam): `outputs_novel/gradcam`
- [Error audit](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/src/analyze_errors.py): `src/analyze_errors.py`
- [Error images and CSV](https://github.com/psvedant/leafnet_mcmd_gradcam/tree/main/outputs_novel/error_analysis): `outputs_novel/error_analysis`

### Prediction API

- [Prediction endpoint](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/app.py): `app.py`
- [Class prediction](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/app.py): `app.py`
- [Prediction heatmap](https://github.com/psvedant/leafnet_mcmd_gradcam/blob/main/app.py): `app.py`

### Other components

- **Plant disease images**
- **Image submitter**

## Connections

- Plant disease images → Stage raw data: stages (evidence: `README.md`)
- Stage raw data → Raw dataset: writes (evidence: `README.md`)
- Raw dataset → Build splits: provides images (evidence: `README.md`)
- Build splits → Train, val, test: creates (evidence: `README.md`)
- Train, val, test → Train and checkpoint: trains on (evidence: `README.md`)
- Custom CNN blocks → Train and checkpoint: builds model for (evidence: `README.md`)
- Train and checkpoint → Trained model: saves (evidence: `README.md`)
- Trained model → Multiclass metrics: evaluates (evidence: `README.md`)
- Train, val, test → Multiclass metrics: supplies test data (evidence: `README.md`)
- Multiclass metrics → Reports and plots: writes (evidence: `README.md`)
- Trained model → Grad-CAM heatmaps: explains predictions (evidence: `README.md`)
- Train, val, test → Grad-CAM heatmaps: supplies test images (evidence: `README.md`)
- Grad-CAM heatmaps → Class heatmaps: writes (evidence: `README.md`)
- Trained model → Error audit: audits errors (evidence: `README.md`)
- Train, val, test → Error audit: supplies test images (evidence: `README.md`)
- Error audit → Error images and CSV: writes (evidence: `README.md`)
- Image submitter → Prediction endpoint: uploads image (evidence: `app.py`)
- Prediction endpoint → Class prediction: predicts (evidence: `app.py`)
- Class prediction → Prediction heatmap: generates heatmap (evidence: `app.py`)
