Overview
Thetrain.py module provides the main training pipeline with experiment tracking, dataset validation, and checkpoint management. It supports both real datasets (Fashion-MNIST) and synthetic data generation.
run_experiment
Main function to run a complete training experiment with tracking and checkpointing.Parameters
Name of a predefined experiment configuration from
EXPERIMENT_CONFIGS, or path to a JSON configuration fileConfiguration Options
The experiment configuration (JSON or predefined) supports the following fields:Architecture specification, e.g.,
[784, 64, 10] for input, hidden, and output layersActivation functions for each layer transition, e.g.,
["relu", "softmax"]Number of training epochs
Learning rate
Training batch size
Random seed for reproducibility
Numeric precision:
"float32", "float16", or "int8"Proportion of training data to use for validation
If
true, generates synthetic random data instead of loading real datasetNumber of synthetic samples to generate (only used when
synthetic_mode=true)Custom path to training dataset (defaults to Fashion-MNIST train path)
Minimum required rows for dataset validation
Automatically download dataset if missing
Expected SHA-256 hash for dataset integrity verification
Behavior
- Configuration Resolution: Loads config from
EXPERIMENT_CONFIGSor JSON file - Seed Initialization: Sets global seed for reproducibility
- Model Creation: Instantiates
NeuralNetworkwith specified architecture - Data Loading: Loads real dataset or generates synthetic data
- Train/Val Split: Splits data according to
val_ratio - Experiment Tracking: Creates experiment record with metadata
- Training: Runs model training with validation
- Checkpoint Saving: Saves model weights to
experiments/checkpoints/ - Logging: Writes experiment history to
experiments/logs/
Output Files
- Checkpoint:
experiments/checkpoints/{experiment_id}_v{version}.npz - History Log:
experiments/logs/{experiment_id}.json
Example Usage
CLI Usage
Run training from the command line:CLI Arguments
Experiment config name or path to JSON config file