# activatedgeek/lenet-5 architecture

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

- Interactive diagram: https://gitdiagram.com/activatedgeek/lenet-5
- Repository: https://github.com/activatedgeek/lenet-5

## Overview

##### Main Components
a. Data Source
- MNIST dataset (external)
- Data loader/preprocessing logic baked into run.py (using torchvision or similar)
b. Model Definition
- lenet.py – defines the LeNet-5 architecture (convolutional, pooling, fully connected layers)
c. Training Orchestrator
- run.py – sets up the training loop:
– Instantiates model, loss fn, optimizer
– Loads batches from MNIST
– Performs forward/backward passes
– Sends scalar metrics (train loss) to Visdom
– Saves/export model as lenet.onnx
d. Visualization Service
- Visdom server (python –m visdom.server) running on localhost:8097
- Receives real-time loss updates via Visdom client API in run.py
e. Model Export and Viewing
- ONNX export (lenet.onnx)
- External viewer (Netron) to inspect the graph

##### Relationships and Data Flows
- MNIST data → (Data Loader) → Model (lenet.py)
- Model forward/backward → Optimizer → Updated model weights
- Loss & epoch metrics → Visdom client → Visdom server → Browser graph
- Final model → ONNX exporter → lenet.onnx → Netron

##### Architectural Patterns & Design Principles
- Pipeline pattern: clear separation of data ingestion, model definition, training loop, visualization, and export
- Modular code: lenet.py (model) vs run.py (orchestration)
- Externalized monitoring: decoupled Visdom server for real-time visualization

##### Key Technologies & Frameworks
- Python 3.x
- PyTorch (inferred via ONNX export, though requirements.txt will specify torch/torchvision)
- Visdom (visualization)
- ONNX (model interchange format)
- Netron (ONNX graph viewer)

## Diagram (Mermaid)

```mermaid
flowchart TD
    MNIST["MNIST Dataset"]:::externalData
    DataLoader["Data Loader / Preprocessing"]:::codeModule
    ModelDef["Model Definition\n(lenet.py)"]:::codeModule
    Training["Training Loop / Orchestrator"]:::codeModule
    VisClient["Visdom Client Integration"]:::codeModule
    Exporter["ONNX Exporter → lenet.onnx"]:::codeModule
    Visdom["Visdom Server\n(real-time loss plots)"]:::service
    Browser["Browser UI"]:::service
    Netron["Netron Viewer\n(ONNX inspection)"]:::service
    Dependencies["Dependencies\n(torch, torchvision, visdom, onnx)"]:::codeModule
    Documentation["Project Documentation"]:::codeModule

    MNIST --> DataLoader
    DataLoader --> ModelDef
    ModelDef --> Training
    Training --> Exporter
    Training -->|metrics| VisClient
    VisClient -.->|realtime loss| Visdom
    Visdom --> Browser
    Exporter -.->|inspect ONNX| Netron
    Dependencies
    Documentation

    click DataLoader "https://github.com/activatedgeek/lenet-5/blob/master/run.py"
    click Training "https://github.com/activatedgeek/lenet-5/blob/master/run.py"
    click VisClient "https://github.com/activatedgeek/lenet-5/blob/master/run.py"
    click Exporter "https://github.com/activatedgeek/lenet-5/blob/master/run.py"
    click ModelDef "https://github.com/activatedgeek/lenet-5/blob/master/lenet.py"
    click Dependencies "https://github.com/activatedgeek/lenet-5/blob/master/requirements.txt"
    click Documentation "https://github.com/activatedgeek/lenet-5/blob/master/README.md"

    classDef codeModule fill:#ADD8E6,stroke:#000;
    classDef externalData fill:#90EE90,stroke:#000;
    classDef service fill:#FFD580,stroke:#000;
```
