r/learnmachinelearning • • 17h ago

Interactive Neural Network Playground in Pygame & pure NumPy — live activation graph, 10 architectures, and GIF interpolation

2 Upvotes

1 comment sorted by

1

u/herbal1st 17h ago

What is happening here?
Instead of storing pixels like a normal image file, this small neural network is learning a math formula that predicts the color (R, G, B) for any (x, y) coordinate—and (x, y, time) for animated GIFs.

What you're seeing on screen:

  • Left: The original target image/GIF.
  • Center: A live "brain scan" of the network's neurons firing as you hover over different pixels (blue = negative values, orange = positive values).
  • Right: What the AI is currently drawing from memory.
  • Infinite Zoom: Because the AI learns a continuous math function rather than a pixel grid, zooming in shows blocky squares on the original image (left) while the AI side (right) stays smooth.
  • Slow-Mo GIF Interpolation: Even though the dancing GIF only has 13 frames, slowing playback down lets the network smoothly blend the motion between frames.

A quick note on image/GIF sharpness:
The reconstructions have a slightly soft, painterly look rather than 100% razor-sharp pixel accuracy. That's an intentional tradeoff: the network is kept tiny (only ~4k–22k weights depending on the mode and preset) so it runs smoothly in real time on a CPU in pure NumPy without a GPU. Packing a full 13-frame animation into ~22,000 numbers pushes that tiny capacity pretty hard, so there's plenty of room to experiment with bigger layers, longer training, or different activation combos like SIN (SIREN).

Under the hood:

  • 100% pure NumPy for the neural network math (no PyTorch or TensorFlow).
  • Pygame (pygame-ce) for the UI, live activation visualizer, and GIF decoding.
  • Interactive Workbench: Press 1–0 to swap between 10 network architectures, Tab to toggle Fourier coordinate encoding (notice how RAW mode at 0:32 can only draw smooth color gradients!), and the arrow keys to cycle each layer's activation function live.

Source Code (Source-Available / Non-Commercial EULA): github.com

Happy to answer any questions about how the math or Pygame UI works!