| 197 | self.dim = dim |
| 198 | |
| 199 | def forward(self, events): |
| 200 | # print({'ici!'}) |
| 201 | # print(len(events)) |
| 202 | epsilon = 10e-3 |
| 203 | B = int(1+events[-1, -1].item()) |
| 204 | # tqdm.write(str(B)) |
| 205 | num_voxels = int(2 * np.prod(self.dim) * B) |
| 206 | C, H, W = self.dim |
| 207 | # print(C,H,W) |
| 208 | vox = events[0].new_full([num_voxels, ], fill_value=0) |
| 209 | # get values for each channel |
| 210 | x, y, t, p, b = events.T |
| 211 | for bi in range(B): |
| 212 | t[events[:, -1] == bi] /= t[events[:, -1] == bi].max() |
| 213 | |
| 214 | idx_before_bins = x \ |
| 215 | + W * y \ |
| 216 | + 0 \ |
| 217 | + W * H * C * p \ |
| 218 | + W * H * C * 2 * b |
| 219 | for i_bin in range(C): |
| 220 | values = torch.zeros_like(t) |
| 221 | values[(t > i_bin/C) & (t <= (i_bin+1)/C)] = 1 |
| 222 | |
| 223 | # draw in voxel grid |
| 224 | idx = idx_before_bins + W * H * i_bin |
| 225 | vox.put_(idx.long(), values, accumulate=True) |
| 226 | |
| 227 | vox = vox.view(-1, 2, C, H, W) |
| 228 | vox = torch.cat([vox[:, 0, ...], vox[:, 1, ...]], 1) # (B, 2, H, W) |
| 229 | return vox |
| 230 | |
| 231 | |