cnn_card
Business card running / showing the internals of a CNN to classify 5x5 digits
cnn_card: a business card that classifies digits
A working business card that runs a small convolutional neural network on 5 by 5 pixel digits and lights up LEDs to show what each layer is doing.
The card and what it shows
The card is a physical demonstration of a CNN. It classifies 5x5 pixel digits and, more interestingly, shows the internal activations for all layers on LEDs, so you see what the network sees at each layer rather than only the final result. The project description puts it in one line: a business card that runs a convolutional neural network to classify small digit images and displays the internal activations for all layers.
The model and the honest overfit
The model is small: three convolutional layers with 4, 8, and 16 filters, plus a dense layer at the output. Training data was manually generated, whatever the author could come up with, and augmented with shifting and random pixel flips. The README is candid that the number of parameters is quite large compared to the number of training samples, so the result is probably mostly overfitting. The author adds that there probably are not many more samples to include anyway.
Driving the hardware
The LEDs and buttons are driven and scanned using multiplexing through two shift registers. The main challenge in the code was making that fast and consistent enough to allow PWM control of the brightness. An auxiliary code directory holds notebooks: one generates the startup animation as a concentric pulse, and another calculates a gamma correction table for the LEDs.
Building the PCB
The PCB was made by elecrow at 1mm thickness with ENIG finish and matte black soldermask. A stencil was ordered alongside it, and hot air with paste soldered everything except the battery holder, which was done manually. For testing the author used a coin cell battery holder from the bill of materials, then replaced it with a CR2032 with tabs soldered on to reduce the thickness a bit.
Battery behavior
The battery math is laid out in the README. In standby the card draws 0.14 microamps, so it should last decades. In use it lasts about 10 hours, drawing less than 10mA at maximum brightness and closer to 2 to 3mA in normal use. After two minutes without input the card goes into standby automatically. White LEDs were chosen because their brightness works best at the low currents involved, and the phosphor makes the light more diffuse.
Community notes