Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Neuromorphic Spiking Neural Network (SNN) Digit Classifier

Brain-Inspired AI for Real-Time Handwritten Digit Recognition using Spiking Neural Networks

Python PyTorch snnTorch Torchvision Streamlit Plotly MIT License

⚑ Brain-Inspired Computing with Spiking Neural Networks

A Neuromorphic AI application that recognizes handwritten digits using biologically inspired Leaky Integrate-and-Fire (LIF) neurons, temporal spike processing, and interactive visualization.


πŸ“– Overview

Neuromorphic Spiking Neural Network (SNN) Digit Classifier is an end-to-end Deep Learning application that classifies handwritten digits (0–9) using Spiking Neural Networks (SNNs) instead of conventional Artificial Neural Networks (ANNs).

Unlike traditional neural networks that process continuous activation values, SNNs communicate using discrete spikes over time, closely resembling how neurons communicate inside the human brain.

The project is built using PyTorch, snnTorch, and Torchvision, and deployed through an interactive Streamlit dashboard where users can draw digits, visualize spike activity, inspect output neuron firing, and observe the decision-making process of a neuromorphic neural network.


🎯 Project Objectives

This project aims to:

  • Learn Neuromorphic AI fundamentals
  • Understand Spiking Neural Networks
  • Simulate biological neuron behavior
  • Train an SNN on the MNIST dataset
  • Visualize temporal spike activity
  • Build an interactive AI dashboard
  • Demonstrate energy-efficient AI concepts

🌟 Features

🧠 Spiking Neural Network

Implements a biologically inspired neural architecture using:

  • Leaky Integrate-and-Fire (LIF) neurons
  • Temporal spike propagation
  • Membrane potential dynamics
  • Spike accumulation
  • Surrogate gradient learning

✍ Interactive Digit Drawing Canvas

Users can:

  • Draw handwritten digits
  • Clear the canvas
  • Predict instantly
  • Observe live inference

⚑ Real-Time Spike Visualization

The dashboard displays:

  • Output neuron spikes
  • Spike counts
  • Raster plots
  • Temporal firing activity
  • Prediction confidence

πŸ“Š Probability Distribution

Visualize:

  • Softmax probabilities
  • Spike accumulation
  • Winning neuron
  • Confidence score

🎨 Modern Dashboard

Built with:

  • Streamlit
  • Plotly
  • Dark Theme UI
  • Interactive Components

🧠 What are Spiking Neural Networks?

Traditional neural networks communicate using continuous numbers.

Neuron A
      β”‚
      β–Ό
Activation = 0.82

Spiking Neural Networks communicate using discrete spikes over time.

Time β†’

Neuron A

0 0 1 0 0 1 1 0 0 1

This temporal behavior closely resembles biological neurons and enables energy-efficient computation suitable for neuromorphic hardware.


βš™ Leaky Integrate-and-Fire (LIF) Neuron

The project uses Leaky Integrate-and-Fire (LIF) neurons.

Each neuron:

  • Integrates incoming current
  • Stores membrane potential
  • Leaks over time
  • Fires when threshold is crossed
  • Resets after firing

Membrane Potential

[ U_t = \beta U_{t-1} + I_t ]

Where

  • (U_t) = Membrane Potential
  • (I_t) = Input Current
  • (\beta) = Leakage Constant

Spike Generation

If

[ U_t \ge U_{threshold} ]

Neuron emits

[ S_t = 1 ]

Otherwise

[ S_t = 0 ]


πŸ— Network Architecture

                    MNIST Image
                     (28 Γ— 28)
                          β”‚
                          β–Ό
                  Flatten (784)
                          β”‚
                          β–Ό
              Fully Connected Layer
                     (784 β†’ 128)
                          β”‚
                          β–Ό
             Leaky Integrate-and-Fire
                    Hidden Layer
                          β”‚
                          β–Ό
              Fully Connected Layer
                     (128 β†’ 10)
                          β”‚
                          β–Ό
             Leaky Integrate-and-Fire
                  Output Neurons
                          β”‚
                          β–Ό
                Spike Accumulation
                          β”‚
                          β–Ό
                 Digit Prediction

⏱ Temporal Processing

Unlike ANNs, inference occurs across 25 simulation time steps.

T = 25

Time β†’

t0
t1
t2
t3
...
t24

Each neuron may fire multiple spikes.

The digit with the highest accumulated spike count is selected.


πŸ”„ Complete ML Pipeline

MNIST Dataset

        β”‚

        β–Ό

Image Preprocessing

        β”‚

        β–Ό

Flatten Input

        β”‚

        β–Ό

LIF Hidden Layer

        β”‚

        β–Ό

Output LIF Layer

        β”‚

        β–Ό

Spike Accumulation

        β”‚

        β–Ό

Predicted Digit

        β”‚

        β–Ό

Interactive Streamlit Dashboard

πŸ“ Project Structure

snn-digit-classifier/
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ model.py
β”œβ”€β”€ train.py
β”‚
β”œβ”€β”€ models/
β”‚   └── snn_mnist.pth
β”‚
β”œβ”€β”€ screenshots/
β”‚
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
└── README.md

βš™ Technology Stack

Programming

  • Python 3.10+

Deep Learning

  • PyTorch
  • snnTorch
  • Torchvision

Neuromorphic Computing

  • Leaky Integrate-and-Fire Neurons
  • Surrogate Gradient Learning
  • Spike Encoding
  • Temporal Learning

Visualization

  • Plotly
  • Streamlit

Scientific Computing

  • NumPy
  • Pillow

πŸš€ Installation

Clone Repository

git clone https://github.com/SHALINISAURAV/snn-digit-classifier.git

cd snn-digit-classifier

Create Virtual Environment

Windows

python -m venv venv

venv\Scripts\activate

macOS/Linux

python3 -m venv venv

source venv/bin/activate

Install Dependencies

pip install --upgrade pip

pip install -r requirements.txt

πŸ‹ Train the Model

python train.py

Training includes:

  • Downloading MNIST
  • Building SNN
  • Forward propagation
  • Spike simulation
  • Surrogate backpropagation
  • Saving trained weights

β–Ά Run the Dashboard

streamlit run app.py

Open

http://localhost:8501

🌐 Live Demo

πŸš€ Streamlit Cloud

https://snn-digit-classifier-mexwdjvrvwct7yefeqf57f.streamlit.app/


πŸ“Έ Screenshots

Home Dashboard

(Add Screenshot)

Drawing Canvas

(Add Screenshot)

Spike Raster Plot

(Add Screenshot)

Prediction Dashboard

(Add Screenshot)

πŸ“Š Model Details

Property Value
Dataset MNIST
Model Spiking Neural Network
Hidden Layer 128 Neurons
Output Layer 10 Neurons
Simulation Time 25 Steps
Neuron Model LIF
Learning Surrogate Gradient
Framework PyTorch + snnTorch

πŸ§ͺ Skills Demonstrated

βœ” Python

βœ” PyTorch

βœ” snnTorch

βœ” Neuromorphic Computing

βœ” Deep Learning

βœ” Artificial Intelligence

βœ” Biological Neural Networks

βœ” Surrogate Gradient Learning

βœ” Streamlit

βœ” Plotly

βœ” Data Visualization

βœ” Interactive Dashboards

βœ” Scientific Computing

βœ” Software Architecture


🧠 Concepts Covered

This project demonstrates:

  • Neuromorphic AI
  • Spiking Neural Networks
  • Temporal Neural Processing
  • Biological Learning
  • Deep Learning
  • Computer Vision
  • MNIST Classification
  • Interactive AI Applications
  • Brain-Inspired Computing
  • Human-Computer Interaction

πŸš€ Future Improvements

Neuromorphic AI

  • Convolutional Spiking Neural Networks
  • Recurrent SNNs
  • Adaptive LIF Neurons
  • STDP Learning Rule
  • Reward-Based Learning

Computer Vision

  • Fashion-MNIST Support
  • EMNIST Support
  • CIFAR10 SNN
  • Real Image Recognition
  • Webcam Digit Detection

Dashboard

  • Live Membrane Potential Visualization
  • Hidden Layer Spike Raster
  • Layer-wise Activation Viewer
  • Confusion Matrix
  • Training Dashboard
  • TensorBoard Integration
  • Docker Deployment
  • Cloud Deployment

🀝 Contributing

Contributions are welcome!

  1. Fork the repository

  2. Create a feature branch

git checkout -b feature-name
  1. Commit your changes
git commit -m "Added new feature"
  1. Push your branch
git push origin feature-name
  1. Open a Pull Request

πŸ“œ License

This project is licensed under the MIT License.


πŸ‘©β€πŸ’» Author

Shalini Saurav

AI Engineer | Deep Learning Engineer | Neuromorphic AI Enthusiast | Machine Learning Developer

Connect with me


⭐ Support

If you found this project helpful,

⭐ Star this repository

🍴 Fork it

πŸ“’ Share it

πŸ’™ Contribute


🧠 Neuromorphic Spiking Neural Network Digit Classifier

Brain-Inspired Computing β€’ Neuromorphic AI β€’ Deep Learning β€’ Interactive Visualization

Built with ❀️ using PyTorch, snnTorch, Streamlit, Plotly, and Python

About

Neuromorphic Spiking Neural Network (SNN) digit classifier built using PyTorch, snnTorch, and Streamlit. Simulates Leaky Integrate-and-Fire (LIF) neuron dynamics with interactive canvas drawing and real-time spike raster plots.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages