A neural network with Qt GUI for training and visualization. Includes XOR gate and support for more datasets (e.g. handwritten digits).
![]() |
![]() |
(Run ./NeuralNetworkGUI)
- Topology – Configure layers (default: 2-4-1 for XOR)
- Training Data – Browse to select a
.txtfile (e.g.data/xor.txtordata/digits.txt) - Load from file – Load topology from the training file
- Create Network – Build network from topology
- Train – Train on the selected data (Do not set the epchos to high on big data sets or many neurons since the training is running on your CPU it will likely freez the application)
- Test / Predict – Enter inputs and run a forward pass
- Click input neurons – Edit values directly in the visualization
With the digits dataset a small 8×8 drawing canvas is available for live prediction. Accuracy hovers around 90%; not ideal, but impressive for a from scratch implementation. Recognition is especially strong for digits like 8, even with distorted or incomplete inputs.
cmakeandmakeQtfor GUI
Neural-Network-CPP/
├── src/
│ ├── core/ # Neural network (Net, Neuron, Connection, TrainingData)
│ └── gui/ # Qt UI (MainWindow, NetworkScene, NeuronItem)
├── tools/ # Training data generators
│ └── generateXorData.cpp
├── data/ # Training data files
│ └── xor.txt
├── main.cpp # CLI entry point
├── main_gui.cpp # GUI entry point
└── CMakeLists.txt
mkdir -p build && cd build
cmake ..
cmake --build .GUI only (Release):
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --target NeuralNetworkGUImacOS (Qt):
cmake -B build -DCMAKE_PREFIX_PATH=$(brew --prefix qt@6)
cmake --build buildGUI (recommended):
# macOS (.app bundle)
open build/NeuralNetworkGUI.app
# Linux / other (plain executable)
./build/NeuralNetworkGUICLI:
# Run from project root so data/xor.txt is found
./build/NeuralNetCLIXOR gate:
./build/GenerateXorData > data/xor.txtHandwritten digits (8×8, 10 classes):
./build/GenerateDigitsData > data/digits.txtUses embedded synthetic patterns (500 samples). For the full 1,797-sample UCI dataset, download optdigits.tes from UCI, place in data/, and run:
./build/GenerateDigitsData data/optdigits.tes > data/digits.txttopology: <input_count> <hidden_1> <hidden_2> ... <output_count>
in: <value1> <value2> ...
out: <target1> <target2> ...

