• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    C++
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run inferences using TensorFlow Lite for Microcontrollers on a Commodore 64.

TensorFlow Lite for Commodore 64s

Run inferences using TensorFlow Lite for Microcontrollers on a Commodore 64.

This project is in no way associated with, or endorsed by, Google Inc. TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

How It Works

TensorFlow Lite for Microcontrollers is an open-source machine learning framework in which a TensorFlow model is built and trained on a host computer. That model is then reduced in size and computational complexity by an exporter that converts it to the TensorFlow Lite format. For the tiniest of compute platforms — microcontrollers — that model is then converted to a C array containing the model structure and any trained parameters, like weights and biases. On the microcontroller, an interpreter parses the C array to extract operations and data to run inferences against new input data.

Given that TF Lite for Microcontrollers runs on some heavily resource-constrained devices, I got to wondering whether or not I could run inferences against these models on a Commodore 64.

To do this, I chose not to use an interpreter. The TF Lite Micro team explains why they did in their paper (i.e. portability, maintainability). And that was a good choice for the project to be sure, but I'm dealing with nearly 40 year old hardware, so I cannot afford the overhead of an interpreter. Instead, I modified the TF Lite Micro source code so that when running an interpreter on the host computer, it will emit all of the important details about the model, e.g.: operations to perform, filter values, biases, etc. Additionally, I analyzed the source code for all operations involved with running the model so that I could reproduce the functionality.

I then parsed that output with a Python script to turn it into C64-compatible BASIC (this could be updated to produce 6502 assembly code, but for this proof of concept, BASIC was actually fast enough).

To test things out, I built TensorFlow's Hello World example that builds and trains a small, 3 layer neural network that learns to approximate the sine function. After running it on the host computer and emitting the model info, I used my parser to create this BASIC code that can be used to run arbitrary inferences against the neural network on a Commodore 64. Each inference takes a few seconds to run on a physical C64 computer.

Since the code running on the C64 is the same thing logically as what runs on the host computer (or microcontroller), it performs equally well in all environments. There is no accuracy reduction from running on the C64.

Media

YouTube Demonstration

Should I be concerned about what my C64 is reading lately?

Running a neural network trained to approximate the sine function on a Commodore 64:

A short sample of the generated C64 BASIC code (full listing here):

10 dim l1(16)
20 dim l2(16)
30 input "enter a number:"; a%
40 a% = int((a% / 0.024574 - 128)+0.5)
50 acc = ((117 + 0) * (a% + 128)) + 6
60 if acc>0 then acc=(acc*1169513172 + 2^30) / 2^31
70 if acc<=0 then acc=(acc*1169513172 + (1-2^30)) / 2^31
80 acc = (int((acc)+0.5) / 2^6) + -128
90 acc = int((acc)+0.5)
100 if acc < -128 then acc = -128
110 if acc > 127 then acc = 127
120 l1(1) = acc
130 acc = ((28 + 0) * (a% + 128)) + 2935
140 if acc>0 then acc=(acc*1169513172 + 2^30) / 2^31
150 if acc<=0 then acc=(acc*1169513172 + (1-2^30)) / 2^31
160 acc = (int((acc)+0.5) / 2^6) + -128
170 acc = int((acc)+0.5)
180 if acc < -128 then acc = -128
190 if acc > 127 then acc = 127

Bill of Materials

  • 1 x Commodore 64 computer

About the Author

Nick A. Bild, MS

More Repositories

1

voice_chatgpt

VoiceGPT is a voice assistant that leverages the powerful ChatGPT chatbot to answer your questions.
Python
320
star
2

local_llm_assistant

World's Easiest GPT-like Voice Assistant
Python
300
star
3

shaides

My AI is so bright, I gotta wear shades.
Python
137
star
4

picoROM

Emulate ROM chips with a Raspberry Pi Pico.
Makefile
102
star
5

freedom_shield

Freedom Shield was developed to protect the rights of individuals to peaceably assemble and petition their government.
61
star
6

c64_gen_ai

Make creative retro game sprites on the Commodore 64 with generative AI.
Python
50
star
7

vectron_64

Custom-built general purpose, programmable, 6502-based computer and operating system.
HTML
45
star
8

speaker_snitch

Speaker Snitch flashes a light when your smart speaker is sending data to the cloud.
C++
37
star
9

browzen

BrowZen correlates your emotional states with the web sites you visit to give you actionable insights about how you spend your time browsing the web.
Python
37
star
10

vectron_vga_plus

Vectron VGA Plus generates a 640x480@60Hz VGA signal and has an interface that works with retro computers or microcontrollers.
C++
35
star
11

c64_watch

C64 Watch is a customized T-Watch 2020 that was inspired by the Commodore 64 computer. It features a C64 theme and a built-in BASIC interpreter.
C
32
star
12

go_motion

Simplify stop motion animation with machine learning.
Python
28
star
13

doom_air

Play Doom on a giant screen using your body as the controller.
Python
26
star
14

schematic-o-matic

Automatically draw a KiCad schematic for a circuit prototyped on a breadboard.
Python
25
star
15

safe_meeting

Safe Meeting keeps an eye on you during your video conferences, and if it sees business-inappropriate attire, the video is immediately muted.
Python
23
star
16

pico_pong

Play gesture-controlled Pong with a Raspberry Pi Pico!
C
21
star
17

shaides_v2

ShAIdes 2.0 is a much smaller, more practical, redesign of the original ShAIdes.
C
21
star
18

vectron_vga

VGA signal generator designed for the Vectron 64 computer.
C++
18
star
19

deepclean

Flag potentially contaminated surfaces for deep cleaning to help prevent the spread of contagious disease.
Python
16
star
20

tipper

Tipper predicts if a pitch will be in or out of the strike zone in real time.
Python
13
star
21

c64_watch_sync

Keep tabs on your fitness with this C64-themed smartwatch that wirelessly syncs data to your Commodore 64 computer.
C
13
star
22

combat

The 2-player only Atari classic Combat can now be played against an AI opponent. It runs entirely on a 2600 — no external processing or sensors involved!
13
star
23

usb_gpio

Add Python programmable GPIO pins to any computer with USBgpio.
Python
13
star
24

vectron_vga_plus_v2

Vectron VGA Plus v2 generates a 640x480@60Hz VGA signal and has an interface that works with retro computers or microcontrollers.
C++
12
star
25

fpga_rom_emulator

FPGA-based ROM emulator dramatically speeds software development time on computers with ROM-based storage.
AGS Script
12
star
26

vectron_65

The Vectron 65 is a 6502 CPU-based breadboard computer. It supports VGA output, keyboard input, boots into a BASIC interpreter, and has lots of GPIOs.
Assembly
12
star
27

fpga_vga_text_mode

Generate a 400x300 @ 60Hz 3-bit color VGA signal, addressable as a 50x30 matrix of characters.
AGS Script
11
star
28

ay-3-8910

Control a General Instrument AY-3-8910 sound generator from a Raspberry Pi.
10
star
29

vectron_handheld

Vectron Handheld is a retro handheld gaming console based on the 6502 CPU.
Assembly
10
star
30

vectron_vr

Virtual Reality Peripheral for Vectron 64
Assembly
9
star
31

fpga_vga

MiniVGA generates a 200x150 @ 60Hz 3-bit color VGA signal for Arduino or retrocomputer use.
AGS Script
9
star
32

light_brakes

Light Brakes are smart glasses that selectively filter out excessively bright spots (e.g. the Sun, headlights, glare) from a wearer's field of vision in real-time.
Python
8
star
33

gi-pi

Control the classic General Instrument SP0256-AL2 speech chip and AY-3-8910 sound generator with a Raspberry Pi and this Python library.
Python
8
star
34

vectron_vga_plus_text_mode

Vectron VGA Plus Text Mode simplifies displaying text with retro computers and microcontrollers by hiding the pixel-level details.
Assembly
8
star
35

memory_pill

Memory Pill passively records the last time a medication bottle was opened to prevent over- and underdosing of medications when you cannot remember if you have already taken a scheduled dose.
C
8
star
36

artemis

Artemis is an eyeglass-mounted device that can be configured to locate a specific type of object, or a person. When the target is found, Artemis will track it with a laser.
Python
8
star
37

laser_blaster

Play the Atari 2600 with a laser gun!
Python
7
star
38

wfh_robot

WFH Bot goes to the office for you so that you can work from home.
Python
7
star
39

arduboy_home

Play Arduboy games on the big screen with the Arduboy Home game console.
AGS Script
7
star
40

pi-64

The Pi64 is a Raspberry Pi 400 that thinks it's a Commodore 64.
Shell
6
star
41

sentinel

Sentinel was designed to provide a subtle reminder not to touch your face for infectious disease prevention.
C++
6
star
42

vectron_ai

Train machines like it's 1979! Play Atari 2600 games with gestures.
Assembly
6
star
43

golf_ace

Learn to putt like your favorite pro golfer with machine learning.
C
6
star
44

newrons

Smart glasses with a gentle memory assist.
C++
5
star
45

aqua

Aqua turns the underpowered Mattel Aquarius into a respectable computer by adding 32 KB of RAM and SD card mass storage.
C++
4
star
46

gemini

Gemini Project demonstrates a method to create a functionally identical copy of software using deep learning.
Python
3
star
47

vectron_65_plus

Vectron 65 Plus is a 6502 CPU-based computer with keyboard support that can run BASIC. It is highly extensible via 32 GPIO pins.
Assembly
3
star
48

journey_to_xenos

Homebrew Atari 2600 game.
Assembly
3
star
49

lcd_display

Control a Hitachi HD44780U compatible LCD character display with a microcontroller.
C++
2
star
50

gaze_estimation

Playing around with NVIDIA's pre-trained models in the Transfer Learning Toolkit on a Jetson.
2
star
51

alt_wii_controller

Mario Kart Wii is a great game, but the controls are awkward. So, I built an alternative controller to play the game with a D-pad.
C++
2
star
52

introvention

Introvention is a wearable device that seeks to diagnose movement disorders earlier than is presently possible by leveraging machine learning.
C++
2
star
53

coleco_adam_usb_keyboard

This adapter enables an unmodified Coleco Adam keyboard to work as a USB keyboard on any modern computer.
C++
2
star
54

eeprom_burner

Burn/read an Atmel AT28C256 EEPROM chip with a microcontroller.
C++
2
star
55

pcjr_gpt3

Ask the world's smartest IBM PCjr anything and it will answer using the GPT-3 deep learning language model.
Python
2
star
56

cura_profile

Ultimaker Cura Config for Monoprice MP Mini Delta 3D Printer
1
star
57

aquarius_cartridge_breakout

This PCB provides access to the Mattel Aquarius' cartridge port via pin headers.
1
star
58

eeprom_burner_mega

Burn/validate 28c256 EEPROMs with an Arduino Mega.
C++
1
star
59

resume

Nick Bild's Resume
1
star
60

tft_lcd_controller

Controller for a TFT LCD display.
C++
1
star
61

graphvr

GraphVR is a virtual reality graphing application for the visualization of genomic data.
C#
1
star
62

6502_monitor

Monitor the address lines of a 6502 processor with a microcontroller.
C++
1
star
63

sonicsight_ar

SonicSight AR provides the hearing-impaired with a visual warning when dangerous sounds (alarms, emergency vehicles, car horns, etc.) are encountered.
C
1
star
64

eeprom_pi

Raspberry Pi-based EEPROM burner.
Python
1
star
65

vaccine

Vaccine is an early software threat detection system inspired by the adaptive immune system and plant communication. It is designed to work in concert with existing antivirus software. Vaccine is a first line of defense -- it senses new threats as they present themselves in the wild, and provides the information needed to quickly "vaccinate" antivirus software to protect against new threats before they spread.
Java
1
star