This repository contains Python code for the paper titled "Neuromorphic Computing Paradigms Enhance Robustness through Spiking Neural Networks."
The project investigates how SNN can improve robustness using temporal processing capabilities.
This repository includes codes for:
- Development of an SNN architecture.
- Evaluation of SNN under adversarial attack.
- Analysis of SNN robustness.
Ensure you have Python 3.8 or later installed. Install the required packages using the following command:
pip install -r requirements.txt- torch >= 2.0.0+cu118
- torchvision >= 0.15.1+cu118
- numpy >= 1.24.2
- matplotlib >= 3.7.1
- tqdm >= 4.61.2
- umap-learn == 0.5.7
- gdown == 5.2.0
- pytorch == 2.4.0 # on cpu
- torchvision == 0.19.0
- numpy >= 1.24.2
- matplotlib >= 3.7.1
- tqdm >= 4.61.2
- gdown == 5.2.0
To install PyTorch, refer to the official PyTorch installation guide.
Typical install time on a "normal" desktop computer depends on the network condition!
part1 corresponds to the results in Prioritizing task-critical temporal information during encoding boosts SNN robustness
part2 corresponds to the results in Training algorithms for SNNs enabling flexible encoding achieve robust generalization
part3 corresponds to the results in Early exiting SNN decoding protects against subsequent perturbations improving robustness
part4 corresponds to the results in SNN employs fused input encoding to enhance performance in complex attacks
|-- global_tools/ # Tools for adversarial attack and for training SNNs
|-- global_configs.py # Script for setting dataset, and encoding methods, as well as url for model checkpoints
|-- data/ # place to save clean datasets
|-- part1/ # Codes evaluating the robustness of SNN with regard to encoding methods
|-- part2/ # Codes evaluating the robustness of SNN with regard to training methods
|-- part3/ # Codes evaluating the robustness of SNN with regard to decoding methods
|-- part4 # Codes evaluating the scability of the proposed methods
|-- part4_attack/ # place to save attacked CIFAR-10 dataset
|-- requirements.txt # Python dependencies
|-- README.md # Project documentation
Go to global_tools/global_configs and set
dataset_path = {
'mnist': your_data_path/mnist,
'fashionmnist': your_data_path/fashionmnist,
'cifar10': your_data_path/cifar10
}To download pretrained checkpoints for evaluation, run
python download_all.pyTo get all data to plot the main figure corresponding to the main results, go to the corresponding directories and run:
python run_all_eval.pyExpected run time on a "normal" desktop computer: within 10 seconds.
To get all data to plot the figures in the supplementary materials, go to the corresponding directories and run:
python run_supp_fig.pyTo train the ANN model in part1, go to part1_tools and run
python run_ANN_train.py -dataset=MNIST -hidden=100 -bb=0 -seed=AThen, to get SNN, run
python run_SNN_convert.py -dataset=MNIST -hidden=100 -pth_file=model_MNIST_seedA.pthTo train the SNN/ANN model in partx, go to partx_tools and run
python run_train.py -config=../net_params/config_nameconfig_name is a placeholder for YAML files in net_params.
Then, to get converted SNN for part2, open run_SNN_convert.py in part2_tools, change seed, and then run
python run_SNN_convert.pyFind configs that have string 'mix' in the name, such as CIFAR10_ResNet18_ACTBP_mix_entropy-CRT.yaml.
Then, to get SNN, go to part4_tools and run
python run_train-mix.py -config=../net_params/config_nameThis project is licensed under the MIT License. See LICENSE for details.