antoniogweb / php2xai-mnist
MNIST classification exercise built on PHP2xAI.
Package info
github.com/antoniogweb/PHP2xAI-mnist
Type:project
pkg:composer/antoniogweb/php2xai-mnist
v0.3.0
2026-02-06 11:14 UTC
Requires
- php: >=8.1
- antoniogweb/php2xai: ^0.3
README
MNIST classification exercise built on PHP2xAI. The project demonstrates dataset preprocessing in PHP, configuration of the computational graph, and training orchestration, while model training and inference are executed by the C++ runtime.
Installation
composer create-project antoniogweb/php2xai-mnist
Training
Run the script from src/:
cd src
php train.php
What it does:
- Reads data from
src/DataLabelInt/Training/train.txtandsrc/DataLabelInt/Training/test.txt. - Trains the model and saves weights to
src/weights.json.
PHP or C++ runtime:
- In
src/train.phpyou will findsetRuntime("CPP"): it uses the C++ runtime. - To use the PHP runtime, replace it with
setRuntime("PHP")or remove the call.
Batch size:
- The second argument of
StreamFileDatasetcontrols the batch size. - In
src/train.php, editnew StreamFileDataset($path."/train.txt", 1024)(and the validation dataset if needed).
Validation
Run the script from src/:
cd src
php validate.php
What it does:
- Loads the model from
src/model.jsonand weights fromsrc/weights.json. - Computes accuracy and inference time on the test set.
PHP or C++ runtime:
- In
src/validate.phpyou will findsetRuntime("CPP"): it uses the C++ runtime. - To use the PHP runtime, replace it with
setRuntime("PHP")or remove the call.
Notes
- If you don't have
train.txtandtest.txtyet, generate them withsrc/create_data_one_file.php(requires images insrc/images/).