Giter Site home page Giter Site logo

Comments (10)

fangwei123456 avatar fangwei123456 commented on June 1, 2024 1

OK, you can try to change

self.register_buffer('alpha', torch.tensor(alpha, dtype=torch.float))

to

self.alpha=alpha.

from spikingjelly.

mountains-high avatar mountains-high commented on June 1, 2024 1

Thank you very much! Finally, it works :)
Thank you for your time, Dr. Wei

from spikingjelly.

Yanqi-Chen avatar Yanqi-Chen commented on June 1, 2024

I guess you install SpikingJelly using pip? If so, you can install it from source again.

git clone https://github.com/fangwei123456/spikingjelly.git
cd spikingjelly
python setup.py install

Since the pypi's version has no compiled CUDA extensions like '_C_neuron'.

from spikingjelly.

huzhoudaxia avatar huzhoudaxia commented on June 1, 2024

You said right and thanks.

from spikingjelly.

mountains-high avatar mountains-high commented on June 1, 2024

Hi there, I'm continuing the fangwei123456/Spike-Element-Wise-ResNet#1

I'm sorry for re-opening this issue. I installed the Anaconda and created a new environment. This time there weren't any setup errors.

1.  (sew) assel@assel-System-Product-Name:~/Desktop/SEW_2$ git clone https://github.com/fangwei123456/spikingjelly.git
Cloning into 'spikingjelly'...
remote: Enumerating objects: 9828, done.
remote: Counting objects: 100% (1093/1093), done.
remote: Compressing objects: 100% (411/411), done.
remote: Total 9828 (delta 891), reused 787 (delta 680), pack-reused 8735
Receiving objects: 100% (9828/9828), 35.44 MiB | 8.39 MiB/s, done.
Resolving deltas: 100% (6406/6406), done.
2.   (sew) assel@assel-System-Product-Name:~/Desktop/SEW_2$ cd spikingjelly/
3.   (sew) assel@assel-System-Product-Name:~/Desktop/SEW_2/spikingjelly$ git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3

HEAD is now at 2958519 add pub list

4.   (sew) assel@assel-System-Product-Name:~/Desktop/SEW_2/spikingjelly$ python setup.py install


CUDA_HOME is None. Install Without CUDA Extension
running install
running bdist_egg
running egg_info
creating spikingjelly.egg-info
writing spikingjelly.egg-info/PKG-INFO
writing dependency_links to spikingjelly.egg-info/dependency_links.txt
......

.....
Using /home/assel/anaconda3/envs/sew/lib/python3.9/site-packages/typing_extensions-4.1.1-py3.9.egg
Searching for six==1.16.0
Best match: six 1.16.0
Processing six-1.16.0-py3.9.egg
six 1.16.0 is already the active version in easy-install.pth

Using /home/assel/anaconda3/envs/sew/lib/python3.9/site-packages/six-1.16.0-py3.9.egg
Finished processing dependencies for spikingjelly==0.0.0.0.4

This time I was able to run setup.py without any errors. However, it still occurs:

(sew) assel@assel-System-Product-Name:~/Desktop/SEW_2/spikingjelly$ python3 test.py 
Traceback (most recent call last):
  File "/home/assel/Desktop/SEW_2/spikingjelly/test.py", line 40, in <module>
    import sew_resnet, spiking_resnet
  File "/home/assel/Desktop/SEW_2/spikingjelly/sew_resnet.py", line 4, in <module>
    from spikingjelly.cext import neuron as cext_neuron
  File "/home/assel/Desktop/SEW_2/spikingjelly/spikingjelly/cext/neuron.py", line 5, in <module>
    import _C_neuron
ModuleNotFoundError: No module named '_C_neuron'

I think this version is spikingjelly==0.0.0.0.4. Could you help please to solve this issue? Thank you!

P.S: My goal was to use pre-trained Imagenet weights which were saved via state_dict. That's the reason why I need to have model architecture.

from spikingjelly.

fangwei123456 avatar fangwei123456 commented on June 1, 2024

@mountains-high
I find that you install without CUDA: CUDA_HOME is None. Install Without CUDA Extension.
'_C_neuron' is a CUDA module.

If you do not have CUDA, you can try to use this code https://github.com/fangwei123456/Spike-Element-Wise-ResNet/tree/new_sj and replace the 'cupy' backend to the 'torch' backend:

https://github.com/fangwei123456/Spike-Element-Wise-ResNet/blob/74b48797bf6fc8e6bb71a867bce13385f280eba5/imagenet/sew_resnet.py#L9

from spikingjelly.

fangwei123456 avatar fangwei123456 commented on June 1, 2024

Another choice is using to this python neuron

from spikingjelly.clock_driven import neuron, layer, surrogate

layer.MultiStepContainer(neuron.IFNode(detach_reset=True, surrogate_function=surrogate.ATan()))

to replace cext_neuron.MultiStepIFNode. The neuron has no parameter, and I think it will not influence the loading of weights.

from spikingjelly.

mountains-high avatar mountains-high commented on June 1, 2024

Dr. Fang Wei,
Thank you very much for all your help and support.

  1. The 1st option (changed 'cupy' into 'torch', but I have CUDA) didn't work. Because that gave
  File "/home/assel/Desktop/SEW_2/spiking_resnet.py", line 13, in create_msif
    return neuron.MultiStepIFNode(detach_reset=True, surrogate_function=surrogate.ATan(), backend='torch')
AttributeError: module 'spikingjelly.clock_driven.neuron' has no attribute 'MultiStepIFNode'
  1. The 2nd option: I changed all "cext_neuron" into "layer" neurons.
#self.sn1 = cext_neuron.MultiStepIFNode(detach_reset=True)
self.sn1 = layer.MultiStepContainer(neuron.IFNode(detach_reset=True, surrogate_function=surrogate.ATan()))

3. 
net = spiking_resnet.spiking_resnet34()
net.load_state_dict(torch.load("spiking_resnet_34_checkpoint_319.pth")['model'])

Output:

loading Net
Traceback (most recent call last):
  File "/home/assel/Desktop/SEW_2/spikingjelly/test.py", line 326, in <module>
    net_teacher.load_state_dict(torch.load("spiking_resnet_34_checkpoint_319.pth")['model'])
  File "/home/assel/anaconda3/envs/sew/lib/python3.9/site-packages/torch-1.10.2-py3.9-linux-x86_64.egg/torch/nn/modules/module.py", line 1482, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for SpikingResNet:
	Missing key(s) in state_dict: "sn1.module.surrogate_function.alpha", "layer1.0.sn1.module.surrogate_function.alpha", "layer1.0.sn2.module.surrogate_function.alpha", "layer1.1.sn1.module.surrogate_function.alpha", "layer1.1.sn2.module.surrogate_function.alpha", "layer1.2.sn1.module.surrogate_function.alpha", "layer1.2.sn2.module.surrogate_function.alpha", "layer2.0.sn1.module.surrogate_function.alpha", "layer2.0.sn2.module.surrogate_function.alpha", "layer2.1.sn1.module.surrogate_function.alpha", "layer2.1.sn2.module.surrogate_function.alpha", "layer2.2.sn1.module.surrogate_function.alpha", "layer2.2.sn2.module.surrogate_function.alpha", "layer2.3.sn1.module.surrogate_function.alpha", "layer2.3.sn2.module.surrogate_function.alpha", "layer3.0.sn1.module.surrogate_function.alpha", "layer3.0.sn2.module.surrogate_function.alpha", "layer3.1.sn1.module.surrogate_function.alpha", "layer3.1.sn2.module.surrogate_function.alpha", "layer3.2.sn1.module.surrogate_function.alpha", "layer3.2.sn2.module.surrogate_function.alpha", "layer3.3.sn1.module.surrogate_function.alpha", "layer3.3.sn2.module.surrogate_function.alpha", "layer3.4.sn1.module.surrogate_function.alpha", "layer3.4.sn2.module.surrogate_function.alpha", "layer3.5.sn1.module.surrogate_function.alpha", "layer3.5.sn2.module.surrogate_function.alpha", "layer4.0.sn1.module.surrogate_function.alpha", "layer4.0.sn2.module.surrogate_function.alpha", "layer4.1.sn1.module.surrogate_function.alpha", "layer4.1.sn2.module.surrogate_function.alpha", "layer4.2.sn1.module.surrogate_function.alpha", "layer4.2.sn2.module.surrogate_function.alpha". 

I think I cannot use these weights.
Thank you again for your help.

Have a nice day!

from spikingjelly.

fangwei123456 avatar fangwei123456 commented on June 1, 2024

RuntimeError: Error(s) in loading state_dict for SpikingResNet: Missing key(s) in state_dict: "sn1.module.surrogate_function.alpha"

It is strange because the surrogate function should not have the learnable parameter:

import torch
from spikingjelly.clock_driven import neuron, layer, surrogate

net = layer.MultiStepContainer(neuron.IFNode(detach_reset=True, surrogate_function=surrogate.ATan()))
print(net.state_dict())
OrderedDict()

from spikingjelly.

mountains-high avatar mountains-high commented on June 1, 2024

In my case when I run above code:

OrderedDict([('module.surrogate_function.alpha', tensor(2.))])

I am using git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3

from spikingjelly.

Related Issues (20)

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.