fangwei123456 / spikingjelly

SpikingJelly is an open-source deep learning framework for Spiking Neural Network (SNN) based on PyTorch.
https://spikingjelly.readthedocs.io
Other
1.33k stars 238 forks source link

关于’spikingjelly/clock_driven/neuron.py‘,#line 30#,cupy报错 #243

Closed xxyll closed 2 years ago

xxyll commented 2 years ago

您好,我最近在尝试复现GitHub上一个SNN backbone+ANN head目标检测的代码。最初按照作者的描述安装了pytorch1.11、spikingjelly0.0.0.0.4等,但出现了AttributeError: module 'spikingjelly.clock_driven.neuron' has no attribute 'MultiStepParametricLIFNode'的问题,看了您其他的回答后重新安装了spikingjelly0.0.0.0.12版本。

之后debug到下方所示的“./spikingjelly/clock_driven/neuron.py", line 30,出现了AssertionError: CuPy is not installed! You can install it from "https://github.com/cupy/cupy"报错。我已按照Cupy官网的指令下载了cupy-cuda116,删除再下载试了很多次仍然出现同一报错,不知是我下载的cupy版本和spikingjelly不兼容,还是其他原因呢

报错位置: def check_backend(backend: str): if backend == 'torch': return elif backend == 'cupy': assert cupy is not None, 'CuPy is not installed! You can install it from "https://github.com/cupy/cupy".' elif backend == 'lava': assert slayer is not None, 'Lava-DL is not installed! You can install it from "https://github.com/lava-nc/lava-dl".' else: raise NotImplementedError(backend)

详细报错: Traceback (most recent call last): File "/home/lxy/.pycharm_helpers/pydev/pydevd.py", line 1491, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/home/lxy/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/object_detection.py", line 137, in main() File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/object_detection.py", line 85, in main module = DetectionLitModule(args) File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/object_detection_module.py", line 24, in init self.backbone = DetectionBackbone(args) File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/detection_backbone.py", line 11, in init self.model = get_model(args) File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/utils.py", line 70, in get_model return vggs[version]( File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/spiking_vgg.py", line 201, in multi_step_spiking_vgg11 return _multi_step_spiking_vgg('vgg11', 'A', num_init_channels, norm_layer, T, multi_step_neuron, kwargs) File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/spiking_vgg.py", line 163, in _multi_step_spiking_vgg return MultiStepSpikingVGG(num_init_channels, cfg=cfgs[cfg], norm_layer=norm_layer, T=T, multi_step_neuron=multi_step_neuron, kwargs) File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/spiking_vgg.py", line 124, in init super().init(num_init_channels, cfg, norm_layer, num_classes, init_weights, File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/spiking_vgg.py", line 30, in init self.features = self.make_layers(num_init_channels, cfg=cfg, File "/home/lxy/Experiment/object-detection-with-spiking-neural-networks/models/spiking_vgg.py", line 70, in make_layers ("act", neuron(**kwargs)), File "/home/lxy/anaconda3/envs/SNN-SJ/lib/python3.8/site-packages/spikingjelly/clock_driven/neuron.py", line 1088, in init check_backend(backend) File "/home/lxy/anaconda3/envs/SNN-SJ/lib/python3.8/site-packages/spikingjelly/clock_driven/neuron.py", line 30, in check_backend python-BaseException assert cupy is not None, 'CuPy is not installed! You can install it from "https://github.com/cupy/cupy".' AssertionError: CuPy is not installed! You can install it from "https://github.com/cupy/cupy".

期盼您的解答,十分感谢!!

fangwei123456 commented 2 years ago

在你的环境下试一下import cupy看是否报错

另外输出一下torch 和cupy的版本

conda list torch
conda list cupy
xxyll commented 2 years ago

conda list torch Name Version Build Channel pytorch-lightning 1.4.4 pypi_0 pypi torch 1.11.0 pypi_0 pypi torchmetrics 0.5.0 pypi_0 pypi torchvision 0.12.0 pypi_0 pypi

import cupy倒是没有报错,但在服务器上执行conda list cupy输出为空,是不是我压根没安装好哇...安装时执行的是$ pip install cupy-cuda116

fangwei123456 commented 2 years ago

看样子你在服务器上没装cupy

xxyll commented 2 years ago

看样子你在服务器上没装cupy

是在服务器上执行的pip install cupy-cuda116,远程连接后在pycharm上调试的。唉不知道为什么装不上,我再研究一下,谢谢你!!!

xxyll commented 2 years ago

看样子你在服务器上没装cupy

抱歉,再次向您提问...cupy还是无法安装,如果使用torch作为backend,是否可以不再安装cupy。但由于出现的是报错不是警告,无法直接忽略掉,想请问可以如何修改,跳过选择cupy作为backend的这一步呢?

fangwei123456 commented 2 years ago

cupy并非必需,不装cupy应该也可以运行的。

xxyll commented 2 years ago

cupy并非必需,不装cupy应该也可以运行的。

嗯嗯,但是debug单步跳转到spikingjelly/clock_driven/neuron.py中def check_backend(backend: str):模块,出现了assertionerror:cupy is not installed,代码运行就停止了,不知道该如何跳过判断选择cupy的这一步。

fangwei123456 commented 2 years ago

设置了使用cupy后端才会跳入这一条语句

https://github.com/fangwei123456/spikingjelly/blob/1171f5249a4ebeace6ab8d6a74d85579fafb93ed/spikingjelly/clock_driven/neuron.py#L29

xxyll commented 2 years ago

啊,我找到问题在哪了。谢谢你,耐心解答我的低级问题!

pangyanhua commented 1 year ago

我也遇到了同样的问题。换成torch后端就没问题,使用cupy后端就有这个问题,我感觉是check_backend函数设置有问题。我pip install cupy 也用 pip install cupy11x, 都是这个问题

Castrol68 commented 1 year ago

啊,我找到问题在哪了。谢谢你,耐心解答我的低级问题!

请问您是怎么解决的,我也遇到了这个问题 assert cupy is not None, 'CuPy is not installed! You can install it from "https://github.com/cupy/cupy".' AssertionError: CuPy is not installed! You can install it from "https://github.com/cupy/cupy".

xxyll commented 1 year ago

啊,我找到问题在哪了。谢谢你,耐心解答我的低级问题!

请问您是怎么解决的,我也遇到了这个问题 assert cupy is not None, 'CuPy is not installed! You can install it from "https://github.com/cupy/cupy".' AssertionError: CuPy is not installed! You can install it from "https://github.com/cupy/cupy".

不好意思我刚看到!过去挺久了 具体的我记不太清 应该是当时我找到了代码里的“backend == 'cupy'” 然后把cupy改成torch就好了。

Castrol68 commented 1 year ago

非常感谢  

è @.***

 

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年9月28日(星期四) 下午2:04 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [fangwei123456/spikingjelly] 关于’spikingjelly/clock_driven/neuron.py‘,#line 30#,cupy报错 (Issue #243)

啊,我找到问题在哪了。谢谢你,耐心解答我的低级问题!

请问您是怎么解决的,我也遇到了这个问题 assert cupy is not None, 'CuPy is not installed! You can install it from "https://github.com/cupy/cupy".' AssertionError: CuPy is not installed! You can install it from "https://github.com/cupy/cupy".

不好意思我刚看到!过去挺久了 具体的我记不太清 应该是当时我找到了代码里的“backend == 'cupy'”,然后把cupy改成torch就好了。

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

songxt3 commented 4 months ago

补充一个如果报错是: assert cupy is not None, 'CuPy is not installed! You can install it from "https://github.com/cupy/cupy".' AssertionError: CuPy is not installed! You can install it from "https://github.com/cupy/cupy". 可以尝试pip install tensorboard 因为neuron.py中import的cu_kernel_opt,是依赖tensorboard的