Errors with fill_tensor and tensor_to_event
PaoloGCD opened this issue · comments
Describe the bug
Two bugs were found in the IO file:
-
fill_tensor() fails when a "graded" tensor is provided. This is because the payload requires slicing in the same way as the event components were done.
-
tensor_to_event() fails when a Torch tensor is provided. For some reason, np.argwhere() of a Torch tensor returns a row vector instead of the expected column vector. This can be solved by using torch.argwhere() when a tensor is provided and np.argwhere() when a NumPy array is provided."
To reproduce current behavior
Steps to reproduce the behavior:
- Code for tensor_to_event() bug
import lava.lib.dl.slayer as slayer
import torch
tensor = torch.rand(2, 10, 10, 5)
tensor[tensor > 0.5] = 0
event_from_tensor = slayer.io.tensor_to_event(tensor)
event_from_numpy = slayer.io.tensor_to_event(tensor.numpy())
print(event_from_numpy.c.shape == event_from_tensor.c.shape)
print(event_from_numpy.t.shape == event_from_tensor.t.shape)
print(event_from_numpy.x.shape == event_from_tensor.x.shape)
print(event_from_numpy.y.shape == event_from_tensor.y.shape)
print(event_from_numpy.p.shape == event_from_tensor.p.shape)
I get this response
False
False
False
False
False
Expected behavior
The answer should be clearly all true since the same data is being processed (the only difference is the data type tensor or numpy).
- Code for fill_tensor() bug.
import lava.lib.dl.slayer as slayer
import torch
tensor = torch.rand(2, 10, 10, 5)
tensor[tensor > 0.5] = 0
event_from_numpy = slayer.io.tensor_to_event(tensor.numpy())
tensor_from_event = event_from_numpy.fill_tensor(torch.zeros(2, 10, 10, 5))
I get this error
Traceback (most recent call last):
File ".../test.py", line 9, in <module>
tensor_from_event = event_from_numpy.fill_tensor(torch.zeros(2, 10, 10, 5))
File ".../anaconda3/envs/lava/lib/python3.10/site-packages/lava/lib/dl/slayer/io.py", line 231, in fill_tensor
empty_tensor[
RuntimeError: shape mismatch: value tensor of shape [467, 467] cannot be broadcast to indexing result of shape [467, 1]
Environment (please complete the following information):
- Device: Laptop
- OS: MacOs
- Lava version: 0.7.0