Skip to content

PyTriton

model_navigator.api.utilities

Public utilities for the Model Navigator API.

UnpackedDataloader(dataloader, unpack_fn)

A wrapper around a SizedDataLoader that applies a function to each sample.

Parameters:

Name Type Description Default
dataloader SizedDataLoader

A SizedDataLoader.

required
unpack_fn Callable

A function that takes a sample and returns a new sample.

required

Returns:

Type Description

An iterator over the samples in the dataloader with the unpack_fn applied.

Example

dataloader = [1, 2, 3] unpacked_dataloader = UnpackedDataloader(dataloader, lambda x: x + 1)

unpacked_dataloader is now [2, 3, 4]

Initialize the UnpackedDataloader.

Source code in model_navigator/api/utilities.py
def __init__(self, dataloader: SizedDataLoader, unpack_fn: Callable):
    """Initialize the UnpackedDataloader."""
    self._dataloader = dataloader
    self._unpack_fn = unpack_fn

__iter__()

Return an iterator over the samples in the dataloader with the unpack_fn applied.

Source code in model_navigator/api/utilities.py
def __iter__(self):
    """Return an iterator over the samples in the dataloader with the unpack_fn applied."""
    for sample in self._dataloader:
        yield self._unpack_fn(sample)

__len__()

Return the number of samples in the dataloader.

Source code in model_navigator/api/utilities.py
def __len__(self):
    """Return the number of samples in the dataloader."""
    return len(self._dataloader)