MNIST LIFF Izhekebich CNN

A fusion of spiking neural networks and CNNs for efficient digit classification

Project Overview

This project dives into the world of spiking neural networks (SNNs) using the Izhikevich neuron model to classify handwritten digits from the MNIST dataset. Paired with a convolutional neural network (CNN), it compares the energy efficiency and accuracy of SNNs against traditional CNNs.

With optimizations like Spike-Timing-Dependent Plasticity (STDP) and sparse weight matrices, the project achieves up to 94% accuracy, showcasing the potential of biologically inspired models for image classification on resource-constrained devices.

"Exploring the balance between biological plausibility and computational efficiency in neural networks."

Technical Details

The SNN was built using Brian2, simulating 1,254,400 synapses with a maximum spike frequency of 20 Hz. The Izhikevich model, known for its computational efficiency, is defined by:

v' = 0.04v² + 5v + 140 - u + I
u' = a(bv - u)
                    

Where v is the membrane potential, u is the recovery variable, and I is the input current.

Parameters a and b were tuned for regular spiking behavior, and STDP was used for learning. Sparse weight matrices (mean ~0.2501, max ~0.5000) were generated with NumPy and stored in .npy format to reduce memory usage.

The CNN, implemented in PyTorch, included Conv2D layers, MaxPooling2D, and fully connected layers with an input shape of (28, 28, 1). Batch normalization and an Input layer resolved shape warnings, achieving 94% accuracy after 10 epochs.

Key Metrics

  • Data Loading: ~3.21 seconds
  • Network Initialization: ~0.42 seconds
  • Accuracy: ~72% (SNN, initial), ~94% (CNN, optimized)
  • Energy per Epoch: Measured for SNN efficiency

Key Features

High Accuracy

Reached ~94% accuracy with CNN and ~72% with SNN, enhanced by hidden layers and STDP.

Energy Efficiency

SNNs consumed less power, ideal for edge devices.

Sparse Weights

Reduced memory with sparse matrices in .npy format.

Visualizations

Generated confusion matrices and energy plots with Matplotlib.

Challenges & Solutions

  • Challenge: Errors in SpikeGeneratorGroup due to invalid spike timings.
    Solution: Adjusted temporal resolution and validated spike intervals.
  • Challenge: Memory errors during SNN training.
    Solution: Used sparse matrices and optimized batch sizes.
  • Challenge: Lower initial SNN accuracy.
    Solution: Added hidden layers and increased epochs.

Visualizations

Visualizations provide insights into model performance:

  • Confusion Matrix: Highlights misclassifications (e.g., 4 vs. 9).
  • Energy Plot: Shows energy consumption per epoch for SNN.
  • Accuracy Plot: Tracks training/validation accuracy for SNN and CNN.
Placeholder for Confusion Matrix

Confusion Matrix

Placeholder for Energy Plot

Energy Plot

Placeholder for Accuracy Plot

Accuracy Plot

Technologies Used

  • Python
  • Brian2
  • NumPy
  • Matplotlib
  • PyTorch
  • Argparse
  • MNIST Dataset

Explore the Code

Check out the full project on GitHub to dive into the implementation details.

View Repository