fangwei123456 / Spike-Element-Wise-ResNet

Deep Residual Learning in Spiking Neural Networks
Mozilla Public License 2.0
140 stars 21 forks source link

Did you perform the spike-element-wise-ResNet over Cifar100? #1

Open manwu1994 opened 3 years ago

manwu1994 commented 3 years ago

I try to replicate your code over Cifar100 and Cifar10. But I can not achieve acceptable accuracy. Did you perform the spike-element-wise-ResNet over Cifar100?

fangwei123456 commented 3 years ago

No, I have not tried CIFAR. The origin resnet is designed for ImageNet, which is much complex than CIFAR. Using the origin resnet on CIFAR may cause overfitting. I suggest that you use the resnet structure in https://github.com/weiaicunzai/pytorch-cifar100 and change residual block to sew block.

JumpAndShoot commented 2 years ago

Which version of torch do u use? I wanna replicate your code,but I get many bug.

fangwei123456 commented 2 years ago

Which version of torch do u use? I wanna replicate your code,but I get many bug.

# Name                    Version                   Build  Channel
pytorch                   1.8.0           py3.8_cuda11.1_cudnn8.0.5_0    pytorch
torchaudio                0.8.0                      py38    pytorch
torchvision               0.9.0                py38_cu111    pytorch

@JumpAndShoot Codes in this repo with SpikingJelly need to build CUDA extension for neurons.

JumpAndShoot commented 2 years ago

Which version of torch do u use? I wanna replicate your code,but I get many bug.

# Name                    Version                   Build  Channel
pytorch                   1.8.0           py3.8_cuda11.1_cudnn8.0.5_0    pytorch
torchaudio                0.8.0                      py38    pytorch
torchvision               0.9.0                py38_cu111    pytorch

@JumpAndShoot Codes in this repo with SpikingJelly need to build CUDA extension for neurons.

How about the spikingjelly?whether it is 0.0.0.0.6

fangwei123456 commented 2 years ago

It is a speicific verison, not 0.0.0.0.6:

git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3

JumpAndShoot commented 2 years ago

May I get your email or qq or WeChat

It is a speicific verison, not 0.0.0.0.6:

git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3

May I get your email or qq or WeChat

fangwei123456 commented 2 years ago

Hi, I suggest to use Github, and our discussion can be available and helpful to others.

git clone https://github.com/fangwei123456/spikingjelly.git
cd spikingjelly
git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3
python setup.py install

What is the error message?

JumpAndShoot commented 2 years ago

Hi, I suggest to use Github, and our discussion can be available and helpful to others.

git clone https://github.com/fangwei123456/spikingjelly.git
cd spikingjelly
git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3
python setup.py install

What is the error message?

If my system is windows,I download the spkingjelly.where I need to put the file to?

JumpAndShoot commented 2 years ago

Hi, I suggest to use Github, and our discussion can be available and helpful to others.

git clone https://github.com/fangwei123456/spikingjelly.git
cd spikingjelly
git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3
python setup.py install

What is the error message?

If my system is windows,I download the spkingjelly.where I need to put the file to?

And where can I download the special version

fangwei123456 commented 2 years ago

Download SpikingJelly's source codes:

git clone https://github.com/fangwei123456/spikingjelly.git

CD to the root dir:

cd spikingjelly

Revert to the specific version:

git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3

Install the specific version:

python setup.py install

BarCodeReader commented 2 years ago

Hi,

Firstly thanks for your contribution.

I tested the code on dvsgestrue...and the best accuracy(top1) I can obtain here is 95.48 instead of 97 in the paper...which i think is a relatively large gap...

thoughts to provide a docker image so everyone is on the same platform?

fangwei123456 commented 2 years ago

@BarCodeReader Sorry, I do not use the docker image. The identical results (e.g., the same tensorboard logs) can not be guaranteed (see https://pytorch.org/docs/stable/notes/randomness.html). But your result 95.48 is too low. In most cases, you will get nearly 97 top1 accuracy.

I just train a network with new version of SpikingJelly and LIF neuron (you only need to change cext.neuron to neuron.MultiStepNeuron(backend='cupy') in smodel.py. The top1 accuracy is 97.22, which only has one more wrong sample than the paper. Here is the training logs, models and codes. You can try it with the new version of SpikingJelly (I recommend to install from source codes, rather than pip). dvsgesture.zip

BarCodeReader commented 2 years ago

Hi @fangwei123456, thanks for your zip file.

I reinstalled the SpikingJelly from source, and its latest now. The MultiStepLIFNode provided in your zip is better than MultiStepParametricLIFNode in the repo, and now my best accuracy is 96.88, which is 1% behind your best score, :)

To have a fair comparison, I ran the experiment 5 times with arbitrary random seeds, without using amp mode. Below is the log compared with yours (with smoothing factor 0.6 in tensorboard). The top navy color one is from your log file, which has 97.22. Screenshot from 2022-02-16 23-17-25

To me, it seems like it's my machine's issue, maybe some libraries version, etc...and sorry to bother again...do you mind sharing your "pip list", so that I can try to find the reason a bit?

fangwei123456 commented 2 years ago

@BarCodeReader

(pytorch-env) wfang@Precision-5820-Tower-X-Series:~$ conda list
# packages in environment at /home/wfang/anaconda3/envs/pytorch-env:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                      1_llvm    conda-forge
absl-py                   0.13.0                   pypi_0    pypi
blas                      1.0                         mkl    defaults
blessings                 1.7                      pypi_0    pypi
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2021.10.26           h06a4308_2    defaults
cachetools                4.2.2                    pypi_0    pypi
certifi                   2021.10.8        py39h06a4308_0    defaults
chardet                   4.0.0                    pypi_0    pypi
cudatoolkit               11.3.1               h2bc3f7f_2    defaults
cupy-cuda111              9.4.0                    pypi_0    pypi
cycler                    0.10.0                   pypi_0    pypi
docopt                    0.6.2                    pypi_0    pypi
fastrlock                 0.6                      pypi_0    pypi
ffmpeg                    4.3                  hf484d3e_0    pytorch
flatbuffers               2.0                      pypi_0    pypi
freetype                  2.10.4               h0708190_1    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gnutls                    3.6.13               h85f3911_1    conda-forge
google-auth               1.32.0                   pypi_0    pypi
google-auth-oauthlib      0.4.4                    pypi_0    pypi
gpustat                   0.6.0                    pypi_0    pypi
grpcio                    1.38.1                   pypi_0    pypi
idna                      2.10                     pypi_0    pypi
joblib                    1.0.1                    pypi_0    pypi
jpeg                      9b                   h024ee3a_2    defaults
kiwisolver                1.3.1                    pypi_0    pypi
lame                      3.100             h7f98852_1001    conda-forge
lcms2                     2.12                 h3be6417_0    defaults
ld_impl_linux-64          2.35.1               hea4e1c9_2    conda-forge
libffi                    3.3                  h58526e2_2    conda-forge
libgcc-ng                 9.3.0               h2828fa1_19    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libstdcxx-ng              9.3.0               h6de172a_19    conda-forge
libtiff                   4.2.0                h85742a9_0    defaults
libuv                     1.40.0               h7b6447c_0    defaults
libwebp-base              1.2.0                h7f98852_2    conda-forge
llvm-openmp               11.1.0               h4bd325d_1    conda-forge
lz4-c                     1.9.3                h9c3ff4c_0    conda-forge
markdown                  3.3.4                    pypi_0    pypi
matplotlib                3.4.2                    pypi_0    pypi
mkl                       2021.2.0           h726a3e6_389    conda-forge
mkl-service               2.4.0            py39h3811e60_0    conda-forge
mkl_fft                   1.3.0            py39h42c9631_2    defaults
mkl_random                1.2.2            py39hde0f152_0    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
nettle                    3.6                  he412f7d_0    conda-forge
ninja                     1.10.2               h4bd325d_0    conda-forge
numpy                     1.20.2           py39h2d18471_0    defaults
numpy-base                1.20.2           py39hfae3a4d_0    defaults
nvidia-ml-py3             7.352.0                  pypi_0    pypi
oauthlib                  3.1.1                    pypi_0    pypi
olefile                   0.46               pyh9f0ad1d_1    conda-forge
onnx                      1.8.0                    pypi_0    pypi
onnxruntime               1.9.0                    pypi_0    pypi
onnxruntime-gpu           1.9.0                    pypi_0    pypi
openh264                  2.1.1                h780b84a_0    conda-forge
openssl                   1.1.1l               h7f8727e_0    defaults
pillow                    8.2.0            py39he98fc37_0    defaults
pip                       21.1.3             pyhd8ed1ab_0    conda-forge
pqi                       2.0.6                    pypi_0    pypi
protobuf                  3.8.0                    pypi_0    pypi
psutil                    5.8.0                    pypi_0    pypi
pyasn1                    0.4.8                    pypi_0    pypi
pyasn1-modules            0.2.8                    pypi_0    pypi
pynvml                    11.4.1                   pypi_0    pypi
pyparsing                 2.4.7                    pypi_0    pypi
python                    3.9.5           h49503c6_0_cpython    conda-forge
python-dateutil           2.8.1                    pypi_0    pypi
python_abi                3.9                      2_cp39    conda-forge
pytorch                   1.10.1          py3.9_cuda11.3_cudnn8.2.0_0    pytorch
pytorch-mutex             1.0                        cuda    pytorch
rarfile                   4.0                      pypi_0    pypi
readline                  8.1                  h46c0cb4_0    conda-forge
requests                  2.25.1                   pypi_0    pypi
requests-oauthlib         1.3.0                    pypi_0    pypi
rsa                       4.7.2                    pypi_0    pypi
scikit-learn              0.24.2                   pypi_0    pypi
scipy                     1.7.0                    pypi_0    pypi
setuptools                57.0.0                   pypi_0    pypi
six                       1.16.0             pyh6c4a22f_0    conda-forge
sklearn                   0.0                      pypi_0    pypi
spikingjelly              0.0.0.0.9                 dev_0    <develop>
sqlite                    3.36.0               h9cd32fc_0    conda-forge
tbb                       2021.2.0             h4bd325d_1    conda-forge
tensorboard               2.5.0                    pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.0                    pypi_0    pypi
threadpoolctl             2.2.0                    pypi_0    pypi
tk                        8.6.10               h21135ba_1    conda-forge
torchaudio                0.10.1               py39_cu113    pytorch
torchvision               0.11.2               py39_cu113    pytorch
tqdm                      4.61.1                   pypi_0    pypi
typing_extensions         3.10.0.0           pyha770c72_0    conda-forge
tzdata                    2021a                he74cb21_0    conda-forge
urllib3                   1.26.6                   pypi_0    pypi
werkzeug                  2.0.1                    pypi_0    pypi
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
zlib                      1.2.11            h516909a_1010    conda-forge
zstd                      1.4.9                ha95c52a_0    conda-forge

(pytorch-env) wfang@Precision-5820-Tower-X-Series:~$ nvidia-smi
Fri Feb 18 09:34:35 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.19.01    Driver Version: 465.19.01    CUDA Version: 11.3     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:17:00.0 Off |                  N/A |
| 19%   33C    P8    16W / 250W |      0MiB / 11011MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  NVIDIA GeForce ...  On   | 00000000:B3:00.0 Off |                  N/A |
| 18%   34C    P8    21W / 250W |      0MiB / 11019MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

You can also compare with the origin logs https://github.com/fangwei123456/Spike-Element-Wise-ResNet/tree/main/origin_logs/dvsgesture/DVSGNetSEW32_b16_lr0.001_T16_Ttrain12_zi_steplr64_0.1_sgd_cnf_add_logs . But the origin env of this machine is no longer available because I have updated pytorch. This pt file checkpoint_max_val_acc1.zip might be the origin model file.

BarCodeReader commented 2 years ago

@fangwei123456 thanks so much for your help and your kindness!

have a nice day!

mountains-high commented 2 years ago

It is a speicific verison, not 0.0.0.0.6:

git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3

Hello! Thank you for your work. Currently, I am using this specific version. I wanted to use pre-trained Imagenet weights. Thus, I need the network architecture, because I found that weights were saved via ['model'] (state_dict). Could you help me please? I faced with this error message:

  File "test.py", line 40, in <module>
    import sew_resnet, spiking_resnet
  File "/home/Desktop/SEW/spikingjelly/sew_resnet.py", line 4, in <module>
    from spikingjelly.cext import neuron as cext_neuron
  File "/home/Desktop/SEW/spikingjelly/spikingjelly/cext/neuron.py", line 5, in <module>
    import _C_neuron
ModuleNotFoundError: No module named '_C_neuron'

Thank you for your time

fangwei123456 commented 2 years ago

@mountains-high _C_neuron is a old CUDA module used in SpikingJelly. You need to use git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3 and install SpikingJelly. Refer to this: https://github.com/fangwei123456/spikingjelly/issues/46 .

mountains-high commented 2 years ago

Thank you for your response. I'm sorry to ask an unrelated question under this opened issue.

  1. git clone https://github.com/fangwei123456/spikingjelly.git
  2. cd spikingjelly/
  3. python setup.py install
    Traceback (most recent call last):
    File "setup.py", line 5, in <module>
    import setuptools
    ImportError: No module named setuptools

    I tried to run "python setup.py install" before git reset --hard 2958519df84ad77c316c6e6fbfac96fb2e5f59a3 and after. But the same error message occurs

fangwei123456 commented 2 years ago

pip install setuptools

mountains-high commented 2 years ago

Thank you. I tried that way, I thought it might be spikingjelly's setuptools.

image

fangwei123456 commented 2 years ago

I suggest that you use anaconda to create a virtual environment, and install pytorch, spikingjelly into this environment to avoid the permission and dependency problem.

mountains-high commented 2 years ago

Thank you very much for your considerations I will try.