This project demonstrates the process of training a backpropagation neural network using Node.js and TensorFlow.js, and transforming the trained model into a format compatible with the Commodore 64 (C64). The project includes image processing, model training, and exporting the model weights in a C64-compatible format.
This was used in the 4k demo 41 Neurons released at X'2026 party.
It uses a 2-byte floating point format FP77, with 7 bits for the mantissa and 7 bits for the exponent . This format has very low precision so the result on the C64 will vary from the training result.
- Image Processing: Converts input images into binary data for training.
- Neural Network Training: Uses TensorFlow.js to train a neural network on the processed image data.
- Model Transformation: Converts the trained model's weights into a format suitable for use on a C64.
- C64 Compatibility: Outputs the model weights as exponent and mantissa values for integration with C64 programs.
- Node.js
- TensorFlow.js
- Additional dependencies (see
package.json)
Using tfjs-node instead of tfjs improves the whole process and makes the training faster (just un-/comment the first lines in the two js files), but the installation is a complete disaster and can take hours of trial and error. You will need to get node-gyp installed and that is where the fun begins. Don't call me for help, I don't remember how I got it working, and it was a nightmare.
- Clone the repository:
git clone https://github.com/rwe1941/c64-backpropagation.git cd c64-backpropagation cd 1 Training - nodeJS npm i
Run the training script to process images, train the neural network, and save the model:
node 1_train_model.jsnode 2_transform_model_to_C64.jsCopy the output from step 2 (starting at MAT1_BASE_EXPONENT) and paste it into main.asm file (Line 250) If you changed the model architecture, you need to update the constants and code in iterateNN in main.asm file as well.
Assemble the whole program with ACME an run it. Have fun!