tonic.prototype.datasets.nmnist
#
Module Contents#
Classes#
Iterable-style DataPipe. |
|
- class tonic.prototype.datasets.nmnist.NMNISTFileReader(dp: Union[torchdata.datapipes.iter.IterDataPipe[str], torchdata.datapipes.iter.IterDataPipe[Tuple[str, BinaryIO]]], dtype: Optional[numpy.dtype] = np.dtype([('x', int), ('y', int), ('t', int), ('p', int)]), keep_compressed: Optional[bool] = False)[source]#
Bases:
torchdata.datapipes.iter.IterDataPipe
[tonic.prototype.datasets.utils._dataset.Sample
]Iterable-style DataPipe.
All DataPipes that represent an iterable of data samples should subclass this. This style of DataPipes is particularly useful when data come from a stream, or when the number of samples is too large to fit them all in memory.
IterDataPipe
is lazily initialized and its elements are computed only whennext()
is called on the iterator of anIterDataPipe
.All subclasses should overwrite
__iter__()
, which would return an iterator of samples in this DataPipe. Calling__iter__
of anIterDataPipe
automatically invokes its methodreset()
, which by default performs no operation. When writing a customIterDataPipe
, users should overridereset()
if necessary. The common usages include resetting buffers, pointers, and various state variables within the customIterDataPipe
.Note
Only one iterator can be valid for each
IterDataPipe
at a time, and the creation a second iterator will invalidate the first one. This constraint is necessary because someIterDataPipe
have internal buffers, whose states can become invalid if there are multiple iterators. The code example below presents details on how this constraint looks in practice. If you have any feedback related to this constraint, please see GitHub IterDataPipe Single Iterator Issue.These DataPipes can be invoked in two ways, using the class constructor or applying their functional form onto an existing
IterDataPipe
(recommended, available to most but not all DataPipes). You can chain multiple IterDataPipe together to form a pipeline that will perform multiple operations in succession.Note
When a subclass is used with
DataLoader
, each item in the DataPipe will be yielded from theDataLoader
iterator. Whennum_workers > 0
, each worker process will have a different copy of the DataPipe object, so it is often desired to configure each copy independently to avoid having duplicate data returned from the workers.get_worker_info()
, when called in a worker process, returns information about the worker. It can be used in either the dataset’s__iter__()
method or theDataLoader
‘sworker_init_fn
option to modify each copy’s behavior.Examples
- General Usage:
>>> # xdoctest: +SKIP >>> from torchdata.datapipes.iter import IterableWrapper, Mapper >>> dp = IterableWrapper(range(10)) >>> map_dp_1 = Mapper(dp, lambda x: x + 1) # Using class constructor >>> map_dp_2 = dp.map(lambda x: x + 1) # Using functional form (recommended) >>> list(map_dp_1) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> list(map_dp_2) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> filter_dp = map_dp_1.filter(lambda x: x % 2 == 0) >>> list(filter_dp) [2, 4, 6, 8, 10]
- Single Iterator Constraint Example:
>>> from torchdata.datapipes.iter import IterableWrapper, Mapper >>> source_dp = IterableWrapper(range(10)) >>> it1 = iter(source_dp) >>> list(it1) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> it1 = iter(source_dp) >>> it2 = iter(source_dp) # The creation of a new iterator invalidates `it1` >>> next(it2) 0 >>> next(it1) # Further usage of `it1` will raise a `RunTimeError`
- Parameters:
dp (Union[torchdata.datapipes.iter.IterDataPipe[str], torchdata.datapipes.iter.IterDataPipe[Tuple[str, BinaryIO]]]) –
dtype (Optional[numpy.dtype]) –
keep_compressed (Optional[bool]) –
- class tonic.prototype.datasets.nmnist.NMNIST(root: os.PathLike, train: Optional[bool] = True, first_saccade_only: Optional[bool] = False, keep_compressed: Optional[bool] = False)[source]#
Bases:
tonic.prototype.datasets.utils._dataset.Dataset
Events have (xytp) ordering.
@article{orchard2015converting, title={Converting static image datasets to spiking neuromorphic datasets using saccades}, author={Orchard, Garrick and Jayawant, Ajinkya and Cohen, Gregory K and Thakor, Nitish}, journal={Frontiers in neuroscience}, volume={9}, pages={437}, year={2015}, publisher={Frontiers} }
- Parameters:
root (string) – Location to save files to on disk.
train (bool) – If True, uses training subset, otherwise testing subset.
first_saccade_only (bool) – If True, only work with events of the first of three saccades. Results in about a third of the events overall.
keep_compressed (Optional[bool]) –
- sensor_size = (34, 34, 2)#