This is code for HoSNN: Adversarially-Robust Homeostatic Spiking Neural Networks with
Adaptive Firing Thresholds

----------------------------------------------------
1.first install the dependencies:

pip install -r requirements.txt

--------------------------------------------------

2.Please use the following commands to run the code in a distributed mode, and you can freely choose the number of GPUs you use. Eg, you're using your 0,1 gpu, so "CUDA_VISIBLE_DEVICES=0,1", and "--nproc_per_node=2":

For FMNIST, -d should be 1: 
CUDA_VISIBLE_DEVICES=0,1 torchrun --rdzv-backend=c10d --rdzv-endpoint=localhost:29506  --nproc_per_node=2 main.py -d 0

For CIFAR10, -d should be 2: (-d should be 2 for CIFAR100 in another folder)
CUDA_VISIBLE_DEVICES=0,1 torchrun --rdzv-backend=c10d --rdzv-endpoint=localhost:29506  --nproc_per_node=2 main.py -d 1

For SVHN, -d should be 3: 
CUDA_VISIBLE_DEVICES=0,1 torchrun --rdzv-backend=c10d --rdzv-endpoint=localhost:29506  --nproc_per_node=2 main.py -d 2


------------------------------------------------------

3.All the running options are placed in the yaml file in the networks folder, and I will choose an example below. Eg for MNIST:<br>

set dynamic_v = False during training, set dynamic_v = True during testing/attacking

DEFAULT:
  dataset: vgg5 		#(you don't need to change)  
  ckpt: 			#(os dirpath. path for model checkpoint)
  cleantrain: True		#(True or False. If True, train a net from scratch)
  advtrain: False               #(True or False. If True, adversarial train a net, need the ckpt model)
  advtest: False		#(True or False. If True, adversarial test the ckpt model)
	
Network:
  epochs: 201
  model: ALIF			#(LIF or ALIF; ALIF is the TA-LIF mode in the paper)
  tau_v: 1.5			#(a positive real number from 1 to inf as tauv in the paper)
  ckpt_v: ./spikedata/mnist/mnist.pt #(os dirpath. path for the NDS, i have prepared a file for you)
  batch_size: 64
  lr: 0.0005
  is_bn: False			#(True or False, whether to use BN layer)
  save_target: False		#(True or False, whether to save your NDS)
  n_steps: 5			#simulation time
  data_path: ./datasets/mnist	
  mean: 0.1307			#mean of the dataset
  std: 0.3081			#std of the dataset
  dataset: MNIST
  loss: "kernel"		#loss, "kernel" for MNIST,CIFAR10 and "softmax" for CIFAR100, don't need to change
  n_class: 10			
  tau_m: 5			#membrane constant
  tau_s: 3			#psc constant
  dynamic_v: False		#set to False for training, set to True for evaluation attack

ATTACK:
  strength: [1/10, 2/10, 3/10, 4/10] #during adv testing,  the strength eps to use
  ft_method: fgm		#during adv training,  the adv method to use
  train: [1/10]			#during adv training,  the eps to use

Layers:
  ...(omitted)

