Giter VIP home page Giter VIP logo

hybrid-snn-conversion's People

Contributors

nitin-rathi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hybrid-snn-conversion's Issues

Pre-trained ResNets

Hi Nitin,

Congratulations on the great work and thanks for making this repository public.
I was wondering if you have any of the pre-trained ResNet ANN models available for download?

Thanks!

SNN Retraining Issue

Hello.

I trained ann model for CIFAR10 by using ann.py.

After that, I run snn.py to train SNN by STDB.

Converting CNN to SNN works fine.
However, accuracy continues to decrease as epoch continues.
The results are the same no matter how small the learning rate is set.
Even if I train the SNN with linear activation, the result is the same.

How can I solve this problem?
I ask for your help, because the learning of SNN is not progressing,

Thank you.

Configuration of ResNet20 for CIFAR10

Dear @nitin-rathi

Can you comment on the parameter choices for ResNet20?

In self_models/resnet.py the ResNet20 is defined in 4 layers with 2 basic blocks in each (num_blocks=[2,2,2,2]) with plane parameters of 64, 128, 256, 512.

In contrast the original paper of He et al. uses only 3 layers with 3 basic blocks in each with plane parameters of 16, 32, 64.

So your model will have tremendously more parameters. Can you comment on your source of the ResNet20 implementation if isn't the paper by He et al.?

about training

if i run the snn.py without a trained ann model,The performance of the network is better than if I run ann.py first and then snn.py, does this mean that in some cases, the hybrid conversion method will degrade the performance of pure snn

How to create the spiking Resnet

Hi, first I appreciate you guys for making this repository public. Recently I am referring to your code and have several questions.

  1. how can I create the spiking Resnet? In other words, how to add the temporal domain in the Resnet?
  2. the expansion is equal to 1. Is it important for the model?
    Would you like to offer some suggestions or ideas? Any help would be appreciated. Thanks very much!

How to run snn.py on multiple GPUs?

Hi,Thank you for the code. I want to run snn.py on multiple GPUs, but when I use model=nn.DataParallel(model), the following error occurs. How can I solve it?

RuntimeError: Caught RuntimeError in replica 0 on device 0.
Original Traceback (most recent call last):
File "D:\0_WorkSpaces\Anaconda3\envs\pytorch04-gpu-ql\lib\site-packages\torch\nn\parallel\parallel_apply.py", line 60, in _worker
output = module(*input, **kwargs)
File "D:\0_WorkSpaces\Anaconda3\envs\pytorch04-gpu-ql\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "E:\GZY\SNN\新建文件夹\hybrid-snn-conversion-master\self_models\vgg_spiking.py", line 255, in forward
self.spike[l] = self.spike[l].masked_fill(out.bool(),t-1)
RuntimeError: arguments are located on different GPUs at C:/w/b/windows/pytorch/aten/src\THC/generic/THCTensorMasked.cu:27

Imagenet pretrained SNN models available ?

Hi, thanks for publishing this repo. May I know if the trained imagenet models are available for download or you have any plan to publish these models in the near future?

Trained Model Issue

Hello.

I want to use your pretrained model (snn_vgg16_cifar10.pth)

But, I got an Error message like below.

File "snn.py", line 474, in
state = torch.load(pretrained_snn, map_location='cpu')
File "/home/sangyeob/env/pytorch-python3.6/lib/python3.6/site-packages/torch/serialization.py", line 386, in load
return _load(f, map_location, pickle_module, **pickle_load_args)
File "/home/sangyeob/env/pytorch-python3.6/lib/python3.6/site-packages/torch/serialization.py", line 573, in _load
result = unpickler.load()
ModuleNotFoundError: No module named 'self_models.spiking_model'

How can I get spiking_model module?
In your self_models file, there is no spiking_model.py.

Thank you.

Forward Function

Hi,
I am referring to your code and have some questions regarding forward function.

I am trying to apply VGG11 on CIFAR-10 dataset.

I applied the Average pooling layer after 2 Convolutional layers.

But in forward function, I am giving the spike of the first conv layer to the second conv layer and then applying avg pool layer to the second spike of conv layer.
In this case, my code is not giving any output and error.

I don't know, what's wrong with this forward function and couldn't fix it.

Can you please tell me what should I do?

Your help will be appreciated.

Below is my code:

class SCNN(nn.Module):
def init(self):
super(SCNN, self).init()
# in_planes, out_planes, stride, padding, kernel_size = cfg_cnn[0]

    self.conv1 = nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, stride=1, padding=1, bias=False)
    self.conv2 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1, bias=False)
    self.max_pool1 = nn.AvgPool2d(kernel_size=2)

    self.conv3 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=1, padding=1, bias=False)
    self.conv4 = nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1, bias=False)
    self.max_pool2 = nn.AvgPool2d(kernel_size=2)

    self.conv5 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1, bias=False)
    self.conv6 = nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1, bias=False)
    self.max_pool3 = nn.AvgPool2d(kernel_size=2)

    self.conv7 = nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1, bias=False)
    self.conv8 = nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1, bias=False)
    self.max_pool4 = nn.AvgPool2d(kernel_size=2)

    # self.conv8 = nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1, bias=False)
    # self.max_pool5 = nn.MaxPool2d(kernel_size=2)

    self.fc0 = nn.Linear(512 * 2 * 2, 4096, bias=False)
    self.fc1 = nn.Linear(4096, 4096, bias=False)
    self.fc2 = nn.Linear(4096, 10)
    # self.fc2 = nn.Linear(1024, 10)

def forward(self, input, time_window=20):
    # batch_size, ch, w, h = input.size()

    c1_mem = c1_spike = Variable(torch.zeros(batch_size, 64, 32, 32).cuda(), requires_grad=False)
    #print(c1_mem.shape)
    c2_mem = c2_spike = Variable(torch.zeros(batch_size, 128, 32, 32).cuda(), requires_grad=False)
    #print(c2_mem.shape)

    c3_mem = c3_spike = Variable(torch.zeros(batch_size, 256, 16, 16).cuda(), requires_grad=False)
    #print(c3_mem.shape)
    c4_mem = c4_spike = Variable(torch.zeros(batch_size, 256, 16, 16).cuda(), requires_grad=False)
    #print(c4_mem.shape)

    c5_mem = c5_spike = Variable(torch.zeros(batch_size, 512, 8, 8).cuda(), requires_grad=False)
    #print(c5_mem.shape)
    c6_mem = c6_spike = Variable(torch.zeros(batch_size, 512, 8, 8).cuda(), requires_grad=False)
    #print(c6_mem.shape)

    c7_mem = c7_spike = Variable(torch.zeros(batch_size, 512, 4, 4).cuda(), requires_grad=False)
    #print(c7_mem.shape)
    c8_mem = c8_spike = Variable(torch.zeros(batch_size, 512, 4, 4).cuda(), requires_grad=False)
    #print(c8_mem.shape)

    h1_mem = h1_spike = h1_sumspike = Variable(torch.zeros(batch_size, 4096).cuda(), requires_grad=False)        #print(h1_mem.shape)
    h2_mem = h2_spike = h2_sumspike = Variable(torch.zeros(batch_size, 4096).cuda(), requires_grad=False)
   # print(h2_mem.shape)
    h3_mem = h3_spike = h3_sumspike = torch.zeros(batch_size, 10, device=device)    #print(h3_mem.shape)

    for step in range(time_window):  # simulation time steps
        x = input > torch.rand(input.size(), device=device)  # prob. firing

        c1_mem, c1_spike = mem_update(self.conv1, x.float(), c1_mem, c1_spike)

        #x = F.avg_pool2d(c1_spike, 2)

        c2_mem, c2_spike = mem_update(self.conv2, c1_spike, c2_mem, c2_spike)
        #x = torch.cat(c1_spike,c2_spike)

        x = self.max_pool1(c2_spike)

        c3_mem, c3_spike = mem_update(self.conv3, x, c3_mem, c3_spike)

        #x = F.avg_pool2d(c3_spike, 2)

        c4_mem, c4_spike = mem_update(self.conv4, c3_spike, c4_mem, c4_spike)
        #x = torch.cat(c3_spike, c4_spike)

        x = self.max_pool2(c4_spike)

        c5_mem, c5_spike = mem_update(self.conv5, x, c5_mem, c5_spike)

        #x = F.avg_pool2d(c5_spike, 2)

        c6_mem, c6_spike = mem_update(self.conv6, c5_spike, c6_mem, c6_spike)
        #x = torch.cat(c5_spike, c6_spike)

        x = self.max_pool3(c6_spike)

        c7_mem, c7_spike = mem_update(self.conv7, x, c7_mem, c7_spike)

        #x = F.avg_pool2d(c7_spike, 2)

        c8_mem, c8_spike = mem_update(self.conv8, c7_spike, c8_mem, c8_spike)
        #x = torch.cat(c7_spike, c8_spike)

        x = self.max_pool4(c8_spike)

        x = x.view(x.size(0), -1)

        h1_mem, h1_spike = mem_update(self.fc0, x, h1_mem, h1_spike)
        h1_sumspike += h1_spike
        h2_mem, h2_spike = mem_update(self.fc1, h1_spike, h2_mem, h2_spike)
        h2_sumspike += h2_spike

        h3_mem, h3_spike = mem_update(self.fc2, h2_spike, h3_mem, h3_spike)
        h3_sumspike += h3_spike

    outputs = h3_sumspike / time_window
    return outputs

Retraining the ANN generated model

Hi I have been trying to reproduce the results by training an ANN from scratch with the same network model of VGG16 as described in your code. Then I tried to use the main.py to convert my saved model .pt to SNN. I am facing following issues:

  1. My ANN training with the model given in self_models/ gives test accuracy around 91% , which is around 1.81% less that what is reported in the paper.
  2. When I use this saved ANN model to convert to SNN domain, the accuracy I get after 20 epochs is around 7% less that the ANN baseline.

Please help me with the issue to reproduce the results.

About snn_vgg11_cifar100

Hi,
Firstly I want to thank you guys for making this repository public.
Recently I am referring to your code and have some questions.

  1. I have tried to use "snn_vgg11_cifar100.pth" for inference. However, the testing accuracy is very low (0.1592 when T=125).
    Then I looked into the log file, which said "Loaded SNN model does not have thresholds" (executing model = nn.DataParallel(model) after the if-block). Is this the reason for the very-low accuracy? Does this mean that I need to retrain the SNN model to obtain a higher accuracy?
    If model = nn.DataParallel(model) was executed before the if-block, the testing accuracy is extreamly low (0.0106 when T=125). And the log file shows "Loaded weight features.0.weight not present in current model".
    Just for comparison, I also tried "snn_vgg16_cifar10.pth" for inference in CIFAR10, and got similar results as your paper reported.

  2. Further, I also tried to train a SNN model based on the supplied "ann_vgg11_cifar100.pth".
    When executing model = nn.DataParallel(model) before the if-block, the training process stopped very soon as "Quitting as the training is not progressing", and the log file shows "Error: Loaded weight classifier.6.weight not present in current model".
    When executing model = nn.DataParallel(model) after the if-block, an error happened ("torch.nn.modules.module.ModuleAttributeError: 'VGG_SNN_STDB' object has no attribute 'module'"), while the log file shows "Success: Loaded classifier.6.weight from ./trained_models/ann/ann_vgg11_cifar100.pth".

Would you please offer some hints or suggestions considering the above observations? By the way, would you kindly offer the download links to the trianed models for ImageNet adopted in your paper?
Any help will be appreciated. Thanks again!

ResNet Training and Conversion

Hello @nitin-rathi, thank you for making this repository public.
Can you give the command line command for training of a ResNet20 on CIFAR10, and its conversion to an SNN. That would be much appreciated.
Kind regards, Anna

I would like to know the running environment of this code.

Hello,

I would like to ask the running environment of this code, such as the version of Python and Pytorch.
Although this is a simple problem, many bugs may appear because of different versions of Pytorch.
Have a nice day! Thanks!

about snn.py

if i just run the snn.py without a pretrained ann model,Does this mean that the network will learn according to spike-based bp, that is, the network becomes a pure snn at this time

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.