Loading video...

Video Failed to Load

Go Home

Just for fun, I've implemented a Convolutional Neural Network (CNN) that predicts handwritten digits... Fully using #glsl and fragment shaders! The model exactly has 2023 parameters and its inner activations are displayed as you draw Try it out live!

118,358 views • 3 years ago •via X (Twitter)

9 Comments

Sebastian Aaltonen's profile picture
Sebastian Aaltonen3 years ago

Nice! To improve the recognition, you should randomly offset the training data. The NIST data is centered. If you offset the data the network learns to detect non-centered digits too.

kishimisu's profile picture
kishimisu3 years ago

Thanks! I did try data augmentation and had way better results in python, but when converting the model to glsl I decided to downscale it a lot to reduce compilation time (it started with 70x more parameters) and it became too small to handle augmented data

Panthaa / Yohan Bensemhoun's profile picture
Panthaa / Yohan Bensemhoun3 years ago

6 is a problem ;)

kishimisu's profile picture
kishimisu3 years ago

Indeed, this is the model’s weak spot! I had to make compromises between the model size and accuracy in order to make it work smoothly inside glsl shaders. 2023 trainable parameters is order of magnitudes lower than typical CNN implementations for this task!

Luky - A$AP Luky's profile picture
Luky - A$AP Luky3 years ago

@__jrm_filipe Niiice! For a reason I never get to have the 6 predicted

kishimisu's profile picture
kishimisu3 years ago

@__jrm_filipe Yes this is the weak spot of this very tiny model!

FuckTheAlgo's profile picture
FuckTheAlgo3 years ago

@mayfer The visualization is super sick

FuckTheAlgo's profile picture
FuckTheAlgo3 years ago

@mayfer Is reimplementing papers in shadertoy the best way to learn 🤔

kishimisu's profile picture
kishimisu3 years ago

@mayfer Not sure if it’s the best way ahah but it definitely made me understand more profoundly how CNNs work as I had to implement every step from scratch

Related Videos

Fukushima's video (1986) shows a CNN that recognises handwritten digits [3], three years before LeCun's video (1989). CNN timeline taken from [5]: ★ 1969: Kunihiko Fukushima published rectified linear units or ReLUs [1] which are now extensively used in CNNs. ★ 1979: Fukushima published the basic CNN architecture with convolution layers and downsampling layers [2]. He called it neocognitron. It was trained by unsupervised learning rules. Compute was 100 times more expensive than in 1989, and a billion times more expensive than today. ★ 1986: Fukushima's video on recognising hand-written digits [3]. ★ 1988: Wei Zhang et al had the first "modern" 2-dimensional CNN trained by backpropagation, and also applied it to character recognition [4]. Compute was about 10 million times more expensive than today. ★ 1989-: later work by others [5]. REFERENCES (more in [5]) [1] K. Fukushima (1969). Visual feature extraction by a multilayered network of analog threshold elements. IEEE Transactions on Systems Science and Cybernetics. 5 (4): 322-333. This work introduced rectified linear units or ReLUs, now widely used in CNNs and other neural nets. [2] K. Fukushima (1979). Neural network model for a mechanism of pattern recognition unaffected by shift in position—Neocognitron. Trans. IECE, vol. J62-A, no. 10, pp. 658-665, 1979. The first deep convolutional neural network architecture, with alternating convolutional layers and downsampling layers. In Japanese. English version: 1980. [3] Movie produced by K. Fukushima, S. Miyake and T. Ito (NHK Science and Technical Research Laboratories), in 1986. YouTube: [4] W. Zhang, J. Tanida, K. Itoh, Y. Ichioka. Shift-invariant pattern recognition neural network and its optical architecture. Proc. Annual Conference of the Japan Society of Applied Physics, 1988. First "modern" backpropagation-trained 2-dimensional CNN, applied to character recognition. [5] J. Schmidhuber (AI Blog, 2025). Who invented convolutional neural networks?

Jürgen Schmidhuber

705,664 views • 7 months ago