Giter VIP home page Giter VIP logo

snn_angular_velocity's Introduction

Event-Based Angular Velocity Regression with Spiking Networks

SNN Regression

This is the code for the paper Event-Based Angular Velocity Regression with Spiking Networks by Mathias Gehrig, Sumit Bam Shrestha, Daniel Mouritzen and Davide Scaramuzza.

You can find a pdf of the paper here. If you use any of this code, please cite the following publication:

@Article{Gehrig20icra,
  author        = {Mathias Gehrig and Sumit Bam Shrestha and Daniel Mouritzen and Davide Scaramuzza},
  title         = {Event-Based Angular Velocity Regression with Spiking Networks},
  journal       = {{IEEE} International Conference on Robotics and Automation (ICRA)},
  url           = {http://rpg.ifi.uzh.ch/docs/ICRA20_Gehrig.pdf},
  year          = 2020
}

Setup

Tested with:

  • PyTorch 1.4.0
  • torchvision 0.5.0
  • strictyaml 1.0.6
  • tqdm 4.43.0

using:

  • Ubuntu 18.04.4 LTS
  • gcc 7.4.0
  • CUDA Tookit 10.0
  • Nvidia Turing GPUs

Data and Log Directory

git clone [email protected]:uzh-rpg/snn_angular_velocity.git
cd snn_angular_velocity

Either set up data and logs directory within the cloned repository with:

export data_dir=$(pwd)/data
export log_dir=$(pwd)/logs
mkdir -p $data_dir $log_dir/train $log_dir/test

or set up an external data and logs directory with symbolic links:

export data_dir="YOUR_DATA_PATH"
export log_dir="YOUR_LOG_PATH"

mkdir -p $data_dir $log_dir/train $log_dir/test
ln -s $data_dir data
ln -s $log_dir logs

or pass the data and logging directories with arguments. For more info:

python test.py -h

Installation with Anaconda

Adapt the CUDA toolkit version according to your setup. We also recommend to build PyTorch from source to avoid conflicts while compiling SLAYER. However the following option might work for you as well:

Create conda environment from scratch with precompiled PyTorch

cuda_version=10.0

conda create -y -n snn python=3.7
conda activate snn
conda install -y pytorch torchvision cudatoolkit=$cuda_version -c pytorch
conda install -y strictyaml tqdm -c conda-forge
conda install -y h5py pyyaml -c anaconda

# Setup for SLAYER
cd slayerpytorch
python setup.py install
cd ..

Download Dataset and Model

Download pretrained model.

wget "http://rpg.ifi.uzh.ch/data/snn_angular_velocity/models/pretrained.pt" -O pretrained/cnn5-avgp-fc1.pt

Download and extract test dataset. This requires zstd which you can get with sudo apt install zstd on Ubuntu.

wget "http://rpg.ifi.uzh.ch/data/snn_angular_velocity/dataset/test.tar.zst" -O $data_dir/test.tar.zst
cd $data_dir
zstd -vd test.tar.zst
tar -xvf test.tar
rm test.*

Similarly, you can get the training dataset

wget "http://rpg.ifi.uzh.ch/data/snn_angular_velocity/dataset/train.tar.zst" -O $data_dir/train.tar.zst

validation dataset

wget "http://rpg.ifi.uzh.ch/data/snn_angular_velocity/dataset/val.tar.zst" -O $data_dir/val.tar.zst

and the original panorama images to recreate the dataset from scratch

wget "http://rpg.ifi.uzh.ch/data/snn_angular_velocity/dataset/imgs.tar" -O $data_dir/imgs.tar

Test

To reproduce the numbers in the paper run:

python test.py

Config file

This uses by default the configuration file in test_config.yaml. Modify the test config if you want to change one of the following parameters:

  • Batch size
  • Number of reader threads
  • GPU device number

Writing predictions to disk

If you would like to write the predictions of the network to disk:

python test.py --write

This will generate the following three files in $log_dir/test/*/out/:

  • indices.npy (sample): for each sample the index of the h5 filename that has been used.
  • groundtruth.npy (sample, angle, time): groundtruth angular velocity
  • predictions.npy (sample, angle, time): predicted angular velocity

snn_angular_velocity's People

Contributors

magehrig 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

snn_angular_velocity's Issues

Some questions about train snn_angular_velocity

hi I'm a student from Hongkong, I'm trying to change this code's dataset and loss function to train a new snn model, but I cannot backpropagate and update the parameters to minimize the loss function. Could you please tell me how can i do this well? Thank you very much.

about data_loader

Hi, thanks for your great work!

the following codes are lines 29 and 30 of data_loader/utils.py, the time_idx is in [0,99], does this mean that only one event will be retained if some events with the same coordinates (ev_xy) and the same time_idx.

spike_tensor = torch.zeros((2, self.height, self.width, self.num_time_bins))
spike_tensor[ev_pol.long(), ev_xy[:, 1].long(), ev_xy[:, 0].long(), time_idx.long()] = 1

Thank you very much!

What GPU are you using?

Hi!
What a wonderful study! Thank you for uploading your codes to github.

When building a neural network, I assume that the time series data from the event camera uses a lot of memory. Have you encountered any GPU memory errors? If you don't mind, I would like to know the model and number of GPUs you are using.

Modifications in slayerPytorch

Could you please explain the modifications in SLAYER that you have made? For instance, I can find slayersnn.loss (which I can't find in the moodified version) in original slayerPytorch. THANK YOU!

Seek for Training Program

Hi lab, thanks for sharing the work. Could you please opensource your training program?

Thank you very much

Batch Size 1 Error

i am a college student from taiwan
i follow the steps finally run python test.py
after running some minutes
i get this result
Loading checkpoint from pretrained/cnn5-avgp-fc1.pt
testing: 100%|████████████████████████████████████████████████| 2495/2495 [05:34<00:00, 7.46it/s]
Traceback (most recent call last):
File "test.py", line 34, in
main()
File "test.py", line 30, in main
tester.test()
File "/home/jfkd147258/snn_angular_velocity/utils/testing.py", line 45, in test
self.data_collector.printErrors()
File "/home/jfkd147258/snn_angular_velocity/utils/testing.py", line 80, in printErrors
print('RMSE: {} deg/s'.format(rmse(pred, gt, deg=True)))
File "/home/jfkd147258/snn_angular_velocity/model/metric.py", line 21, in rmse
rmse = np.mean(np.sqrt(np.sum(np.square(pred - gt), axis=1).flatten()))
ValueError: operands could not be broadcast together with shapes (7485,97) (2495,3,97)

can you help me where i was wrong...thank you

Mind if we contact us by email?

thank you very much
I'm a rookie..so need yout help

Can I train the model with test.tar.zst ?

Hello, I am in the beginning phase to learn how to train SNN with Slayer framework. And I find this project a very good resource. I went through your code but I can't find the code to train the model. Did I make a mistake or can you make this part of code available (if possible). Thanks!

issues about dataset and input/output of network

hi.
I'm trying to verify your code . I have some issues:
1.Test dataset has 2495 files of sequence.
I have read the .h5 file,it appear that:

ang_ts
/ang_ts
(100,)
readh5.py:11: H5pyDeprecationWarning: dataset.value has been deprecated. Use dataset[()] instead.
  print(f[key].value)
[  1000   2000   3000   4000   5000   6000   7000   8000   9000  10000
  11000  12000  13000  14000  15000  16000  17000  18000  19000  20000
  21000  22000  23000  24000  25000  26000  27000  28000  29000  30000
  31000  32000  33000  34000  35000  36000  37000  38000  39000  40000
  41000  42000  43000  44000  45000  46000  47000  48000  49000  50000
  51000  52000  53000  54000  55000  56000  57000  58000  59000  60000
  61000  62000  63000  64000  65000  66000  67000  68000  69000  70000
  71000  72000  73000  74000  75000  76000  77000  78000  79000  80000
  81000  82000  83000  84000  85000  86000  87000  88000  89000  90000
  91000  92000  93000  94000  95000  96000  97000  98000  99000 100000]
ang_xyz
/ang_xyz
(100, 3)
[[ 6.6531079  -5.61633841 -1.34149749]
 [ 6.65008525 -5.62166236 -1.33530828]
 [ 6.64708    -5.62695878 -1.32909642]
 [ 6.6440922  -5.63222761 -1.3228621 ]
 [ 6.64112191 -5.63746875 -1.3166055 ]
 [ 6.63816918 -5.64268212 -1.31032681]
 [ 6.63523407 -5.64786765 -1.30402624]
 [ 6.63231662 -5.65302524 -1.29770397]
 [ 6.62941691 -5.65815483 -1.2913602 ]
 [ 6.62653497 -5.66325632 -1.28499512]
 [ 6.62367086 -5.66832965 -1.27860893]
 [ 6.62082462 -5.67337473 -1.27220181]
 [ 6.61799632 -5.6783915  -1.26577397]
 [ 6.615186   -5.68337987 -1.2593256 ]
 [ 6.61239371 -5.68833977 -1.2528569 ]
 [ 6.6096195  -5.69327113 -1.24636806]
 [ 6.60686342 -5.69817388 -1.23985928]
 [ 6.60412551 -5.70304794 -1.23333076]
 [ 6.60140582 -5.70789325 -1.22678269]
 [ 6.5987044  -5.71270975 -1.22021528]
 [ 6.59602129 -5.71749735 -1.21362872]
 [ 6.59335654 -5.722256   -1.20702322]
 [ 6.59071019 -5.72698563 -1.20039896]
 [ 6.58808229 -5.73168618 -1.19375616]
 [ 6.58547288 -5.73635758 -1.187095  ]
 [ 6.582882   -5.74099977 -1.1804157 ]
 [ 6.5803097  -5.74561269 -1.17371845]
 [ 6.577756   -5.75019628 -1.16700345]
 [ 6.57522097 -5.75475049 -1.1602709 ]
 [ 6.57270462 -5.75927525 -1.15352102]
 [ 6.57020702 -5.7637705  -1.14675399]
 [ 6.56772818 -5.7682362  -1.13997002]
 [ 6.56526815 -5.77267229 -1.13316931]
 [ 6.56282697 -5.77707871 -1.12635208]
 [ 6.56040468 -5.78145541 -1.11951851]
 [ 6.5580013  -5.78580235 -1.11266881]
 [ 6.55561688 -5.79011946 -1.10580319]
 [ 6.55325145 -5.79440671 -1.09892185]
 [ 6.55090504 -5.79866404 -1.092025  ]
 [ 6.54857769 -5.8028914  -1.08511283]
 [ 6.54626943 -5.80708876 -1.07818556]
 [ 6.54398028 -5.81125606 -1.07124339]
 [ 6.54171029 -5.81539327 -1.06428652]
 [ 6.53945948 -5.81950033 -1.05731516]
 [ 6.53722789 -5.82357722 -1.05032952]
 [ 6.53501553 -5.82762388 -1.04332979]
 [ 6.53282245 -5.83164028 -1.03631619]
 [ 6.53064867 -5.83562638 -1.02928893]
 [ 6.52849421 -5.83958215 -1.0222482 ]
 [ 6.5263591  -5.84350754 -1.01519422]
 [ 6.52424337 -5.84740252 -1.00812719]
 [ 6.52214704 -5.85126707 -1.00104732]
 [ 6.52007014 -5.85510114 -0.99395481]
 [ 6.51801269 -5.8589047  -0.98684987]
 [ 6.51597472 -5.86267773 -0.97973272]
 [ 6.51395624 -5.86642019 -0.97260354]
 [ 6.51195729 -5.87013205 -0.96546256]
 [ 6.50997787 -5.8738133  -0.95830998]
 [ 6.50801802 -5.87746389 -0.95114601]
 [ 6.50607774 -5.88108382 -0.94397085]
 [ 6.50415707 -5.88467304 -0.93678472]
 [ 6.50225601 -5.88823155 -0.92958781]
 [ 6.50037459 -5.89175931 -0.92238034]
 [ 6.49851283 -5.89525631 -0.91516251]
 [ 6.49667073 -5.89872253 -0.90793454]
 [ 6.49484832 -5.90215794 -0.90069663]
 [ 6.49304561 -5.90556254 -0.89344898]
 [ 6.49126262 -5.9089363  -0.88619181]
 [ 6.48949936 -5.91227921 -0.87892532]
 [ 6.48775584 -5.91559125 -0.87164972]
 [ 6.48603207 -5.91887241 -0.86436522]
 [ 6.48432807 -5.92212269 -0.85707202]
 [ 6.48264385 -5.92534206 -0.84977034]
 [ 6.48097942 -5.92853052 -0.84246038]
 [ 6.47933478 -5.93168805 -0.83514234]
 [ 6.47770995 -5.93481466 -0.82781644]
 [ 6.47610494 -5.93791033 -0.82048288]
 [ 6.47451976 -5.94097506 -0.81314187]
 [ 6.4729544  -5.94400885 -0.80579362]
 [ 6.47140888 -5.94701168 -0.79843833]
 [ 6.4698832  -5.94998356 -0.79107621]
 [ 6.46837737 -5.95292448 -0.78370747]
 [ 6.4668914  -5.95583446 -0.77633231]
 [ 6.46542528 -5.95871347 -0.76895094]
 [ 6.46397902 -5.96156154 -0.76156357]
 [ 6.46255262 -5.96437865 -0.75417039]
 [ 6.46114608 -5.96716482 -0.74677163]
 [ 6.45975941 -5.96992005 -0.73936749]
 [ 6.45839261 -5.97264434 -0.73195816]
 [ 6.45704567 -5.97533771 -0.72454386]
 [ 6.45571859 -5.97800015 -0.71712479]
 [ 6.45441138 -5.98063169 -0.70970116]
 [ 6.45312402 -5.98323232 -0.70227316]
 [ 6.45185653 -5.98580206 -0.69484102]
 [ 6.45060889 -5.98834093 -0.68740492]
 [ 6.44938109 -5.99084893 -0.67996509]
 [ 6.44817315 -5.99332608 -0.67252171]
 [ 6.44698504 -5.99577239 -0.66507499]
 [ 6.44581676 -5.99818789 -0.65762514]
 [ 6.44466831 -6.00057259 -0.65017236]]
ev_pol
/ev_pol
(820160,)
[0 1 0 ... 1 1 0]
ev_ts
/ev_ts
(820160,)
[     0      0      0 ...  99999 100000 100000]
ev_xy
/ev_xy
(820160, 2)
[[227  27]
 [ 70 109]
 [174  49]
 ...
 [ 57  57]
 [214  95]
 [176  83]]

I think it's not a event stream.

2.The output result of network is same to paper :

Relative error 0.26
RMSE (deg/s) 66.3

But I can't understand the output data :

-`indices.npy` (sample): for each sample the index of the h5 filename that has been used.
- `groundtruth.npy` (sample, angle, time): groundtruth angular velocity
- `predictions.npy` (sample, angle, time): predicted angular velocity

I have read
indices is [ 543 1399 790 ... 2252 1227 2031]
groundtruth is

[[[ 1.23120809e+00  1.23108244e+00  1.23095679e+00 ...  1.21944654e+00
    1.21932995e+00  1.21921360e+00]
  [-8.62108648e-01 -8.62062216e-01 -8.62015545e-01 ... -8.56755912e-01
   -8.56691957e-01 -8.56627822e-01]
  [ 1.20203447e+00  1.20219719e+00  1.20235980e+00 ...  1.21781826e+00
    1.21798074e+00  1.21814334e+00]]

 [[-2.87437868e+00 -2.87453699e+00 -2.87469578e+00 ... -2.89159918e+00
   -2.89179540e+00 -2.89199185e+00]
  [-1.14775813e+00 -1.14840424e+00 -1.14904785e+00 ... -1.19784296e+00
   -1.19822359e+00 -1.19860148e+00]
  [ 7.71361411e-01  7.69754887e-01  7.68147290e-01 ...  6.10988259e-01
    6.09295666e-01  6.07602477e-01]]

 [[-6.46835685e-01 -6.46642089e-01 -6.46447718e-01 ... -6.24390006e-01
   -6.24120414e-01 -6.23850107e-01]
  [-8.45656276e-01 -8.45022917e-01 -8.44389796e-01 ... -7.85124183e-01
   -7.84510970e-01 -7.83898056e-01]
  [ 1.74235022e+00  1.74272406e+00  1.74309778e+00 ...  1.77815449e+00
    1.77851796e+00  1.77888131e+00]]

 ...

 [[-2.24842763e+00 -2.24766421e+00 -2.24690294e+00 ... -2.18509436e+00
   -2.18456388e+00 -2.18403602e+00]
  [-4.48431540e+00 -4.48441935e+00 -4.48452139e+00 ... -4.48527002e+00
   -4.48518229e+00 -4.48509264e+00]
  [-1.09440553e+00 -1.09551287e+00 -1.09662235e+00 ... -1.21012306e+00
   -1.21138918e+00 -1.21265662e+00]]

 [[ 1.65566623e-01  1.65563673e-01  1.65560707e-01 ...  1.65280834e-01
    1.65277883e-01  1.65274948e-01]
  [-5.43570340e-01 -5.43571293e-01 -5.43572307e-01 ... -5.43665111e-01
   -5.43666124e-01 -5.43667078e-01]
  [-1.04799472e-01 -1.04799092e-01 -1.04798712e-01 ... -1.04758650e-01
   -1.04758188e-01 -1.04757719e-01]]

 [[-7.56417809e-04 -4.34344140e-04 -1.12539965e-04 ...  2.91988160e-02
    2.94937734e-02  2.97884401e-02]
  [-1.38769343e-01 -1.38370365e-01 -1.37971133e-01 ... -9.90170687e-02
   -9.85966399e-02 -9.81759951e-02]
  [-1.33957493e+00 -1.33961582e+00 -1.33965659e+00 ... -1.34283960e+00
   -1.34286582e+00 -1.34289181e+00]]]

predicitons is

[[[ 0.          0.          0.         ...  3.480029    3.525945
    3.5745003 ]
  [ 0.          0.          0.         ... -1.1882674  -1.1582054
   -1.1241378 ]
  [ 0.          0.          0.         ...  0.2809324   0.31340265
    0.33595416]]

 [[ 0.          0.          0.         ... -3.21242    -3.2171721
   -3.226446  ]
  [ 0.          0.          0.         ... -0.7546066  -0.74881047
   -0.7447754 ]
  [ 0.          0.          0.         ...  1.1208755   1.1560589
    1.1889876 ]]

 [[ 0.          0.          0.         ... -0.5004051  -0.5111589
   -0.5246059 ]
  [ 0.          0.          0.         ... -0.7192388  -0.71740854
   -0.71479684]
  [ 0.          0.          0.         ...  1.5251882   1.5263648
    1.526502  ]]

 ...

 [[ 0.          0.          0.         ... -1.5828651  -1.5827643
   -1.5872508 ]
  [ 0.          0.          0.         ... -4.619734   -4.5607567
   -4.510894  ]
  [ 0.          0.          0.         ... -1.1843331  -1.2015867
   -1.220317  ]]

 [[ 0.          0.          0.         ... -0.03957559 -0.05267291
   -0.06466625]
  [ 0.          0.          0.         ... -0.54420936 -0.50234264
   -0.4619537 ]
  [ 0.          0.          0.         ...  0.14749646  0.1418699
    0.14284319]]

 [[ 0.          0.          0.         ... -0.052111   -0.05420378
   -0.05268159]
  [ 0.          0.          0.         ... -0.21521878 -0.20370902
   -0.19437169]
  [ 0.          0.          0.         ... -0.29295668 -0.3017923
   -0.31572875]]]


Is it right? I don't know what it means

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.