# yamato-uebayashi/number_recognizer architecture

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

- Interactive diagram: https://gitdiagram.com/yamato-uebayashi/number_recognizer
- Repository: https://github.com/yamato-uebayashi/number_recognizer

## Overview

This is a terminal-based handwritten-digit OCR application. Its main workflow trains a configurable neural network on EMNIST data and saves it, or loads a saved model for either batch evaluation or prediction on a selected handwritten image. The graph separates those user-facing modes, model computation, and binary data/model handling. The training, evaluation, and manual-prediction branches are documented in the README; implementation excerpts show their orchestration in `src/main.rs`.

Main entry points: [`src/binary_load.rs`](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/binary_load.rs) (Binary reader), [`src/main.rs`](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs) (Manual image test), [`src/light_network.rs`](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/light_network.rs) (Inference network), [`save_datas`](https://github.com/yamato-uebayashi/number_recognizer/tree/main/save_datas) (Saved models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["User workflows"]
  node_training["Train model<br/>[main.rs]"]
  node_auto_eval["Automatic evaluation<br/>[main.rs]"]
  node_manual_test["Manual image test<br/>[main.rs]"]
end

subgraph group_model["Neural networks"]
  node_network_train["Trainable network<br/>[network.rs]"]
  node_network_infer["Inference network<br/>[light_network.rs]"]
end

subgraph group_io["Data and model I/O"]
  node_emnist["EMNIST data"]
  node_handwritten["Handwritten images"]
  node_binary_load["Binary reader<br/>[binary_load.rs]"]
  node_model_save["Model writer<br/>[binary_save.rs]"]
  node_saved_models[("Saved models")]
  node_test_image_dir[("Test image files")]
end

node_user(("Terminal user"))

node_user -->|"selects and configures"| node_training
node_user -->|"selects model"| node_auto_eval
node_user -->|"selects model"| node_manual_test
node_training -->|"loads training data"| node_binary_load
node_emnist -->|"provides digit data"| node_binary_load
node_training -->|"trains via backpropagation"| node_network_train
node_training -->|"saves trained model"| node_model_save
node_model_save -->|"writes model files"| node_saved_models
node_auto_eval -->|"loads test data and header"| node_binary_load
node_auto_eval -->|"reads selected model"| node_saved_models
node_auto_eval -->|"runs predictions"| node_network_infer
node_manual_test -->|"loads model header"| node_binary_load
node_manual_test -->|"reads selected model"| node_saved_models
node_manual_test -->|"selects image file"| node_test_image_dir
node_test_image_dir -.->|"provides image bytes"| node_binary_load
node_manual_test -->|"runs prediction"| node_network_infer
node_network_infer -->|"loads neuron parameters"| node_binary_load
node_network_infer -->|"reuses activation function"| node_network_train
node_binary_load -.->|"reads neuron data"| node_saved_models

click node_training "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs"
click node_auto_eval "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs"
click node_manual_test "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs"
click node_network_train "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/network.rs"
click node_network_infer "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/light_network.rs"
click node_binary_load "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/binary_load.rs"
click node_model_save "https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/binary_save.rs"
click node_saved_models "https://github.com/yamato-uebayashi/number_recognizer/tree/main/save_datas"
click node_test_image_dir "https://github.com/yamato-uebayashi/number_recognizer/tree/main/test_image"

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_training,node_auto_eval,node_manual_test,node_user toneBlue
class node_network_train,node_network_infer toneAmber
class node_emnist,node_handwritten,node_binary_load,node_model_save,node_saved_models,node_test_image_dir toneMint
```

## Components

### User workflows

- [Train model](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs): `src/main.rs`
- [Automatic evaluation](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs): `src/main.rs`
- [Manual image test](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/main.rs): `src/main.rs`

### Neural networks

- [Trainable network](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/network.rs): `src/network.rs`
- [Inference network](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/light_network.rs): `src/light_network.rs`

### Data and model I/O

- **EMNIST data**
- **Handwritten images**
- [Binary reader](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/binary_load.rs): `src/binary_load.rs`
- [Model writer](https://github.com/yamato-uebayashi/number_recognizer/blob/main/src/binary_save.rs): `src/binary_save.rs`
- [Saved models](https://github.com/yamato-uebayashi/number_recognizer/tree/main/save_datas): `save_datas`
- [Test image files](https://github.com/yamato-uebayashi/number_recognizer/tree/main/test_image): `test_image`

### Other components

- **Terminal user**

## Connections

- Terminal user → Train model: selects and configures (evidence: `README.md`)
- Terminal user → Automatic evaluation: selects model (evidence: `README.md`)
- Terminal user → Manual image test: selects model (evidence: `README.md`)
- Train model → Binary reader: loads training data (evidence: `src/main.rs`)
- EMNIST data → Binary reader: provides digit data
- Train model → Trainable network: trains via backpropagation (evidence: `src/main.rs`)
- Train model → Model writer: saves trained model (evidence: `README.md`)
- Model writer → Saved models: writes model files (evidence: `src/binary_save.rs`)
- Automatic evaluation → Binary reader: loads test data and header (evidence: `src/main.rs`)
- Automatic evaluation → Saved models: reads selected model (evidence: `README.md`)
- Automatic evaluation → Inference network: runs predictions (evidence: `src/main.rs`)
- Manual image test → Binary reader: loads model header (evidence: `src/main.rs`)
- Manual image test → Saved models: reads selected model (evidence: `README.md`)
- Manual image test → Test image files: selects image file (evidence: `src/main.rs`)
- Test image files → Binary reader: provides image bytes
- Manual image test → Inference network: runs prediction (evidence: `src/main.rs`)
- Inference network → Binary reader: loads neuron parameters (evidence: `src/light_network.rs`)
- Inference network → Trainable network: reuses activation function (evidence: `src/light_network.rs`)
- Binary reader → Saved models: reads neuron data
