:py:mod:`tonic.sliced_dataset`
==============================

.. py:module:: tonic.sliced_dataset


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   tonic.sliced_dataset.SlicedDataset



Functions
~~~~~~~~~

.. autoapisummary::

   tonic.sliced_dataset.save_metadata
   tonic.sliced_dataset.load_metadata



.. py:function:: save_metadata(path, metadata)


.. py:function:: load_metadata(path)


.. py:class:: SlicedDataset


   The primary use case for a SlicedDataset is to cut existing examples in a dataset into
   smaller chunks. For that it takes an iterable dataset and a slicing method as input. It then
   generates metadata about the slices and where to find them in each original sample. The new
   dataset length will be the sum of all slices across samples.

   :param dataset: a dataset object which implements __getitem__ and __len__ methods.
   :param slicer: a function which implements the tonic.slicers.Slicer protocol, meaning that
                  it doesn't have to inherit from it but implement all its methods.
   :param metadata_path: filepath where slice metadata should be stored, so that it does not
                         have to be recomputed the next time. If None, will be recomputed
                         every time.
   :param transform: Transforms to be applied on the data
   :param target_transform: Transforms to be applied on the label/targets
   :param transforms: A callable of transforms that is applied to both data and labels at the same time.

   .. py:attribute:: dataset
      :type: collections.abc.Iterable

      

   .. py:attribute:: slicer
      :type: tonic.slicers.Slicer

      

   .. py:attribute:: metadata_path
      :type: str | None

      

   .. py:attribute:: transform
      :type: collections.abc.Callable | None

      

   .. py:attribute:: target_transform
      :type: collections.abc.Callable | None

      

   .. py:attribute:: transforms
      :type: collections.abc.Callable | None

      

   .. py:method:: __post_init__()

      Will try to read metadata from disk to know where slices start and stop for each sample.

      If no metadata_path is provided or no file slice_metadata.h5 is found in that path,
      metadata will be generated from scratch.


   .. py:method:: generate_metadata()

      Slices every sample in the wrapped dataset and returns start and stop metadata for each
      slice.


   .. py:method:: __getitem__(item) -> Any


   .. py:method:: __len__()



