fangwei123456 / spikingjelly

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

Issue in SHD dataset when trying to use integrate by fixed duration #361

Closed Thvnvtos closed 1 year ago

Thvnvtos commented 1 year ago

The issue is in spikingjelly.datasets.shd specifically in : integrate_events_by_fixed_duration_shd(events: Dict, duration: int, W: int)

x = events['x']
t = events['t']
N = t.size

frames = []
left = 0
right = 0
while True:
    t_l = t[left]
    while True:
        if right == N or t[right] - t_l > duration:
            break
        else:
            right += 1

The values of events['t'] are in seconds (s) array([0. , 0.001833, 0.002167, ..., 0.698 , 0.6997 , 0.7007 ], dtype=float16)

Since the duration parameter is specified to be an int, we can't use this function correctly. Using a duration that is in milliseconds (ms) yields wrong data like this:

output

A simple solution is to convert events['t'] to milliseconds (ms):

t = 1000 * events['t']

which results in correct integration by duration:

output

I've opened a pull request for this change, if it looks ok.

fangwei123456 commented 1 year ago

Thanks! I have merged your PR.

fangwei123456 commented 1 year ago

This is a fatal bug, and I had added it to the bug report in https://github.com/fangwei123456/spikingjelly/blob/master/bugs.md.