Transformations#

Transforms are common event transformations. They can be chained together using Compose. Additionally, there is the tonic.functional module. Functional transforms give fine-grained control over the transformations. This is useful if you have to build a more complex transformation pipeline.

class tonic.transforms.Compose(transforms: Callable)[source]#

Composes several transforms together. This a literal copy of torchvision.transforms.Compose function for convenience.

Parameters

transforms (list of Transform objects) – list of transform(s) to compose. Can combine Tonic, PyTorch Vision/Audio transforms.

Example

>>> transforms.Compose([
>>>     transforms.Denoise(filter_time=10000),
>>>     transforms.ToFrame(n_time_bins=3),
>>> ])

Transforms on events#

CenterCrop(sensor_size, size)

Crops events at the center to a specific output size.

CropTime([min, max])

Drops events with timestamps below min and above max.

Denoise(filter_time)

Drops events that are spatio-temporally not sufficiently close enough to other events in the sample.

Decimation(n)

Deterministically drops every nth event for every spatial location x (and potentially y).

DropEvent(p)

Randomly drops events with probability p.

DropEventByTime([duration_ratio])

Drops events in a certain time interval with a length proportional to a specified ratio of the original length.

DropEventByArea(sensor_size[, area_ratio])

Drops events located in a randomly chosen box area.

EventDrop(sensor_size)

Applies EventDrop transformation from the paper "EventDrop: Data Augmentation for Event-based Learning".

DropPixel([coordinates, hot_pixel_frequency])

Drops events for individual pixels.

Downsample([time_factor, spatial_factor])

Multiplies timestamps and spatial pixel coordinates with separate factors.

MergePolarities()

Sets all polarities to zero.

RandomCrop(sensor_size, target_size)

Crops the sensor size to a smaller size in a random location.

RandomFlipLR(sensor_size[, p])

Flips events in x with probability p.

RandomFlipUD(sensor_size[, p])

Flips events in y with probability p.

RandomFlipPolarity([p])

Flips polarity of individual events with p.

RandomTimeReversal([p, flip_polarities])

Reverses temporal order of events with probability p.

SpatialJitter(sensor_size[, var_x, var_y, ...])

Changes x/y coordinate for each event by adding samples from a multivariate Gaussian distribution.

TimeJitter(std[, clip_negative, sort_timestamps])

Changes timestamp for each event by adding samples from a Gaussian distribution.

RefractoryPeriod(delta)

Sets a refractory period for each pixel, during which events will be ignored/discarded.

TimeAlignment()

Removes offset for timestamps, so that first event starts at time zero.

TimeSkew(coefficient[, offset])

Skew all event timestamps according to a linear transform.

UniformNoise(sensor_size, n)

Adds a fixed number of n noise events that are uniformly distributed across sensor size dimensions such as x, y, t and p.

Event Representations#

NumpyAsType(dtype)

Change dtype of numpy ndarray to custom dtype.

ToAveragedTimesurface(sensor_size[, ...])

Create averaged timesurfaces for each event.

ToFrame(sensor_size[, time_window, ...])

Accumulate events to frames by slicing along constant time (time_window), constant number of events (spike_count) or constant number of frames (n_time_bins / n_event_bins).

ToSparseTensor(sensor_size[, time_window, ...])

PyTorch sparse tensor drop-in replacement for ToFrame.

ToImage(sensor_size)

Counts up all events to a single image of size sensor_size.

ToTimesurface(sensor_size[, ...])

Create global or local time surfaces for each event.

ToVoxelGrid(sensor_size, n_time_bins)

Build a voxel grid with bilinear interpolation in the time domain from a set of events.

ToBinaRep([n_frames, n_bits])

Takes T*B binary event frames to produce a sequence of T frames of N-bit numbers.

Target transforms#

ToOneHotEncoding(n_classes)

Transforms one or more targets into a one hot encoding scheme.

Repeat(n_repeat)

Copies target n times.

Functional transforms in numpy#

crop_numpy(events, sensor_size, target_size)

Crops the sensor size to a smaller sensor.

decimate_numpy(events, n)

Returns 1/n events for each pixel location.

denoise_numpy(events[, filter_time])

Drops events that are 'not sufficiently connected to other events in the recording.' In practise that means that an event is dropped if no other event occured within a spatial neighbourhood of 1 pixel and a temporal neighbourhood of filter_time time units.

drop_event_numpy(events, drop_probability)

Randomly drops events with drop_probability.

drop_by_time_numpy(events[, duration_ratio])

Drops events in a certain time interval with a length proportional to a specified ratio of the original length.

drop_by_area_numpy(events, sensor_size[, ...])

Drops events located in a randomly chosen box area.

drop_pixel_numpy(events, coordinates)

Drops events for pixel locations that fire

drop_pixel_raster(raster, coordinates)

Drops events for pixel locations

identify_hot_pixel(events, hot_pixel_frequency)

Identifies pixels that fire above above a certain frequency, averaged across whole event recording.

identify_hot_pixel_raster(events, ...)

Identifies pixels that fire above a certain predefined spike amount, supports both

refractory_period_numpy(events, ...)

Sets a refractory period for each pixel, during which events will be ignored/discarded.

spatial_jitter_numpy(events, sensor_size[, ...])

Changes x/y coordinate for each event by adding samples from a multivariate Gaussian distribution.

time_jitter_numpy(events[, std, ...])

Changes timestamp for each event by drawing samples from a Gaussian distribution and adding them to each timestamp.

time_skew_numpy(events, coefficient[, offset])

Skew all event timestamps according to a linear transform, potentially sampled from a distribution of acceptable functions.

to_averaged_timesurface(events[, ...])

Representation that creates averaged timesurfaces for each event for one recording.

to_frame_numpy(events, sensor_size[, ...])

Accumulate events to frames by slicing along constant time (time_window), constant number of events (event_count) or constant number of frames (n_time_bins / n_event_bins).

to_timesurface_numpy(events, sensor_size[, ...])

Representation that creates timesurfaces for each event in the recording.

to_voxel_grid_numpy(events, sensor_size[, ...])

Build a voxel grid with bilinear interpolation in the time domain from a set of events.

to_bina_rep_numpy(event_frames[, n_frames, ...])

Representation that takes T*B binary event frames to produce a sequence of T frames of N-bit numbers.