Edge AI / PyTorch to C++

From-scratch training loop to embedded inference

Small neural nets, built close to the metal.

A compact MLP is trained in PyTorch with manual forward pass, BCE loss, backprop, and gradient descent. The learned weights are exported for a C++ inference path, with int8 quantization as the edge deployment target.

7-12-8-1MLP architecture
1200manual epochs
int8deployment target
$ ready
model: Titanic survival MLP
input features: Pclass, Sex, Age, SibSp, Parch, Fare, Embarked
export: weights/*.txt + biases/*.txt

Pipeline

01Normalize

Clean tabular inputs and freeze train-set mean/std for test parity.

02Train

Manual tensor math, sigmoid output, BCE loss, and gradient updates.

03Export

Weights and biases are written into plain text files for C++ loading.

04Quantize

Inference path moves toward compact int8 arithmetic for edge devices.

The demo below simulates the training trace from the project structure; the repository contains the actual PyTorch and C++ source.

Training Trace

Loss
--
Accuracy
--
Model size
--