BrainCog Cognitive Intelligence Engine
repository·main·Indexed 20 days ago
https://github.com/braincog-x/brain-cogAn open-source spiking neural network (SNN) based cognitive intelligence engine for brain-inspired AI, brain simulation, and embodied AI/robotics. It includes implementations for Drosophila-inspired decision-making, PL-SDQN, reward-modulated SNNs for swarm collision avoidance, and knowledge representation. The framework supports multiscale brain structure simulations (including Human PFC and Corticothalamic models) and hardware acceleration on Xilinx Zynq Ultrascale FPGAs via FireFly.
What's inside BrainCog
- BrainCog supports research and implementation in Software-Hardware Co-design, specifically focusing on hardware acceleration for Spiking Neural Networks (SNNs) and systolic matrix engines. Key projects include the FireFly series of FPGA accelerators and SpinalDLA for DSP optimization on FPGAs.
Supported neuromorphic datasets in BrainCog
mainBrainCog includes integrated support for several standard neuromorphic and event-based datasets, making them available for brain-inspired AI research and simulation. Supported datasets include:
- DVSGesture: 11 hand gestures from 29 subjects under 3 illumination conditions (recorded using DVS128).
- DVSCIFAR10: 10,000 event streams converted from the frame-based CIFAR10 dataset.
- NCALTECH101: 100 object classes plus a background class, captured using an ATIS sensor on a motorized pan-tilt unit.
- ES-ImageNet: 1,000 categories converted from 1,300,000 ImageNet frame-based images using Omnidirectional Discrete Gradient (ODG).
- N-Omniglot: 1,623 categories of handwritten characters (20 samples per class) acquired via a DVS acquisition platform.
Reproduce Spiking Transformers with BrainCog
mainThis example directory provides implementations of Spiking Transformer architectures reproduced using the BrainCog framework. It includes models like Spikformer (ICLR 2023), Spike-driven Transformer (Nips 2023), and Spike-driven Transformer V2 (ICLR 2024). These implementations are intended to be merged into the main BrainCog repository.Overview of DSD-SNN for Continual Learning
mainDynamic Structure Development of Spiking Neural Networks (DSD-SNN) is designed for efficient and adaptive continual learning. It employs two primary mechanisms:
- Dynamic Structure Adjustment: The network grows new neurons and prunes redundant ones to increase memory capacity while reducing computational overhead.
- Knowledge Transfer: It overlaps shared structures to leverage knowledge acquired from previous tasks, allowing a single network to support multiple incremental tasks.
The implementation is validated against multiple Task-Incremental Learning (TIL) and Class-Incremental Learning (CIL) benchmarks.
Configure neuron numbers and connectome power in Human Brain Simulation
mainWhen simulating human or macaque brain models, you can customize the simulation by modifying parameters within the main function of the
.pyfiles. Specifically, you can flexibly set:nsz: The number of neurons in each region.asz: The connectome power between regions.
Configure Macaque Brain Simulation parameters
mainYou can customize the scale and connectivity of the brain simulation by modifying the main function in the
.pyfiles (e.g.,brainSimMaq.py).Specifically, you can flexibly set the following parameters:
nsz: The number of neurons in each brain region.asz: The connectome power (connectivity strength) between regions.
Requirements for Causal Reasoning SNN
mainTo run the CRSNN example, ensure the following Python packages are installed in your environment:
numpyscipypytorch >= 1.7.0torchvision
Run the PL-SDQN model
mainThe PL-SDQN (Potential Based Normalization for Spiking Deep Q Network) implementation is used to solve the spike feature information vanishing problem. To run the training process, execute the
main.pyscript located in thesdqndirectory.Prerequisite: You must install the
tianshouframework before running this model.python ./sdqn/main.pyConvert an ANN to an SNN using the ANN-SNN conversion method
mainTo train a deep spiking neural network (SNN) using the ANN-SNN conversion method, you must first prepare a PyTorch-based Artificial Neural Network (ANN). This involves replacing
ReLUandMaxPoolinglayers in your PyTorch model with compatible alternatives to ensure the model can be successfully converted into an SNN for complex tasks.Workflow:
- Train the ANN: Run the initial training script to obtain a well-trained ANN.
- Run SNN Inference: Use the converted script to perform inference using the spiking neural network.
# 1. Train the well-trained ANN python CIFAR10_VGG16.py # 2. Run the SNN inference process python converted_CIFAR10.pyInstall BrainCog
mainTo get started with BrainCog, follow the official installation guide. The guide provides instructions for setting up the environment required for brain-inspired AI research and simulation.
Available versions:
Install PettingZoo
mainTo use the SMAC environments with the PettingZoo multi-agent API, you must first install the
pettingzoopackage via pip.pip install pettingzooRequirements for BAE-SNN example
mainTo run the BAE-SNN (Brain-Inspired Affective Empathy Computational Model) example, ensure the following Python packages are installed in your environment:
numpyscipypytorch >= 1.7.0torchvision