neuromorphs / tonic

Publicly available event datasets and transforms.
https://tonic.readthedocs.io
GNU General Public License v3.0
208 stars 47 forks source link

Poor handling of empty data in Compose #292

Open bauerfe opened 2 months ago

bauerfe commented 2 months ago

Currently, the Compose class does not apply transforms to empty event arrays. I see that this behavior has been introduced in 4763042 to address #256 .

The problem with this is that first, it's silent. It should at least warn when this happens, because this is behavior is not necessarily expected. Second, it's not always desired. To give a concrete example:

I am slicing my recordings into smaller samples, then use ToFrame to convert the events into frames, along with some other transformations. These transforms are wrapped in Compose. Some of the sliced samples happen to be empty. Normally, ToFrame would simply transform that into a raster of correct shape, with all 0s. However, because the sample is empty, Compose does not apply the transform, and returns the original empty array. Because this is a completely different format than expected subsequent code breaks. Because this happened silently, it was hard to track down the issue.

My suggestion(s) would therefore be:

  1. Change the behavior so that it also applies also the transforms to empty arrays (which is at least intuitive), or at least make it optional.
  2. If keeping the current behavior, at least raise a warning when this happens.