Skip to content

Commit

Permalink
update docs notebook with new ToTimesurface transform
Browse files Browse the repository at this point in the history
  • Loading branch information
biphasic committed Jul 2, 2023
1 parent 5245159 commit 44bf3b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 32 deletions.
21 changes: 1 addition & 20 deletions docs/gallery/representations/plot_totimesurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
ToTimesurface
=============
:class:`~tonic.transforms.ToTimesurface` creates local or global time surfaces for each event.
:class:`~tonic.transforms.ToTimesurface` creates global time surfaces at a specific time interval dt.
"""

import tonic

nmnist = tonic.datasets.NMNIST("../../tutorials/data", train=False)
events, label = nmnist[0]


####################################
# ToTimesurface global
# --------------------------------

transform = tonic.transforms.ToTimesurface(
sensor_size=nmnist.sensor_size,
tau=30000,
Expand All @@ -25,17 +20,3 @@
frames = transform(events)

ani = tonic.utils.plot_animation(frames)


####################################
# ToTimesurface local
# --------------------------------

transform = tonic.transforms.ToTimesurface(
sensor_size=nmnist.sensor_size, surface_dimensions=(9, 9), tau=100000, decay="exp"
)

frames = transform(events)

# only plot a few of them
ani = tonic.utils.plot_animation(frames[::70])
2 changes: 1 addition & 1 deletion docs/getting_involved/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To download a dataset, Tonic makes use of a copy of pytorch vision's tools that
`here <https://github.com/neuromorphs/tonic/blob/develop/tonic/datasets/download_utils.py>`_.
Cloud providers such as Dropbox, Google Drive, OneDrive etc. are usually not straightforward
to automatically download from, so if the dataset owner provides multiple mirrors,
prefer a simple REST-like webpage such as https://www.neuromorphic-vision.com/public/downloads/.
prefer a simple REST-like webpage.

The trickier question is the one of file decoding. There exist a variety of file formats that
events and related data are saved in, including .txt, .aedat, .dat, .es, .mat, .hdf5, .rosbag
Expand Down
12 changes: 11 additions & 1 deletion docs/getting_started/nmnist.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "72ab4fec-4fe8-49cc-867f-6a77bcfaa062",
"metadata": {
Expand Down Expand Up @@ -37,6 +38,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "6e9f45be-20da-44f8-962b-2b842fc862df",
"metadata": {},
Expand All @@ -56,6 +58,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "dba2d3f0-f82b-4f16-a06f-97669b73bec4",
"metadata": {},
Expand All @@ -82,6 +85,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "dcfd768d-0a7f-48c8-b1d1-6f80d0b516a4",
"metadata": {},
Expand Down Expand Up @@ -112,6 +116,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "9733a1da-96a5-4ab1-ad0e-d0d46f7a305c",
"metadata": {},
Expand All @@ -137,6 +142,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "10406fbc-ddb2-4104-9a0d-ab375f3e653c",
"metadata": {
Expand Down Expand Up @@ -167,6 +173,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "5c9d5bb7-8658-409a-bcc7-24c7e0587479",
"metadata": {},
Expand All @@ -182,7 +189,7 @@
"outputs": [],
"source": [
"surfaces = transforms.ToTimesurface(\n",
" sensor_size=sensor_size, surface_dimensions=None, tau=10000, decay=\"exp\"\n",
" sensor_size=sensor_size, dt=10000, tau=30000,\n",
")(events_denoised)\n",
"\n",
"n_events = events_denoised.shape[0]\n",
Expand All @@ -196,6 +203,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "a167e44a-39d8-4e42-b5e5-39a9e9179463",
"metadata": {},
Expand All @@ -220,6 +228,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "b2f027cc-55ba-46b6-848d-deedf4e5a3e4",
"metadata": {},
Expand All @@ -245,6 +254,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "aac04620-cf13-4c03-b653-7d3520d52380",
"metadata": {},
Expand Down
14 changes: 4 additions & 10 deletions tonic/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,18 +904,12 @@ def __call__(self, events):

@dataclass(frozen=True)
class ToTimesurface:
"""Create global or local time surfaces for each event. Modeled after the paper Lagorce et al.
2016, Hots: a hierarchy of event-based time-surfaces for pattern recognition
https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7508476.
"""Create global time surfaces at a specific time interval dt.
Parameters:
sensor_size: a 3-tuple of x,y,p for sensor_size
surface_dimensions (int, int): width does not have to be equal to height, however both numbers have to be odd.
if surface_dimensions is None: the time surface is defined globally, on the whole sensor grid.
tau (float): time constant to decay events around occuring event with.
delta_t (float): the interval at which the time-surfaces are accumulated, if set 0 number of time-surfaces will
equal to the number of events. (defaults to 0.0)
decay (str): can be either 'lin' or 'exp', corresponding to linear or exponential decay.
sensor_size: A 3-tuple of x,y,p for sensor_size
dt (float): The interval at which the time-surfaces are accumulated.
tau (float): Time constant to decay events with.
"""

sensor_size: Tuple[int, int, int]
Expand Down

0 comments on commit 44bf3b6

Please sign in to comment.