API

benzina.torch.dataloader

class benzina.torch.dataloader.DataLoader(dataset, batch_size=1, shuffle=False, sampler=None, batch_sampler=None, collate_fn=<sphinx.ext.autodoc.importer._MockObject object>, drop_last=False, timeout=0, shape=None, device=None, multibuffering=3, seed=None, warp_transform=None, norm_transform=None, bias_transform=None)[source]

Loads images from a benzina.torch.dataset.Dataset. Encapsulates a sampler and data processing transformations.

Parameters:
  • dataset (benzina.torch.dataset.Dataset) – dataset from which to load the data.
  • batch_size (int, optional) – how many samples per batch to load (default: 1).
  • shuffle (bool, optional) – set to True to have the data reshuffled at every epoch (default: False).
  • sampler (torch.utils.data.Sampler, optional) – defines the strategy to draw samples from the dataset. If specified, shuffle must be False.
  • batch_sampler (torch.utils.data.Sampler, optional) – like sampler, but returns a batch of indices at a time. Mutually exclusive with batch_size, shuffle, sampler, and drop_last.
  • collate_fn (callable, optional) – merges a list of samples to form a mini-batch.
  • drop_last (bool, optional) – set to True to drop the last incomplete batch, if the dataset size is not divisible by the batch size. If False and the size of dataset is not divisible by the batch size, then the last batch will be smaller. (default: False)
  • timeout (numeric, optional) – if positive, the timeout value for collecting a batch. Should always be non-negative. (default: 0)
  • shape (int or tuple of ints, optional) – set the shape of the samples. Note that this does not imply a resize of the image but merely set the shape of the tensor in which the data will be copied.
  • device (torch.device, optional) – set the device to use. Note that only CUDA devices are supported for the moment. (default: None)
  • multibuffering (int, optional) – set the size of the multibuffering buffer. (default: 3).
  • seed (int, optional) – set the seed for the random transformations.
  • warp_transform (benzina.torch.operations.WarpTransform or iterable of float, optional) – set the warp transformation or use as the arguments to initialize a WarpTransform.
  • norm_transform (benzina.torch.operations.NormTransform or float or iterable of float, optional) – set the normalization transformation. Values to multiply a pixel’s channels with. Note that this transformation is applied after bias_transform.
  • bias_transform (benzina.torch.operations.BiasTransform or float, optional) – set the bias transformation. Values to substract a pixel’s channels with. Note that this transformation is applied after norm_transform.

benzina.torch.operations

class benzina.torch.operations.WarpTransform[source]

Interface class that represents a warp transformation as a combined rotation, scale, skew and translation 3 x 3 matrix. The transformation is called for each sample of a batch.

class benzina.torch.operations.NormTransform[source]

Interface class that represents a normalization transformation. The transformation is called for each sample of a batch.

class benzina.torch.operations.BiasTransform[source]

Interface class that represents a bias transformation. The transformation is called for each sample of a batch.

class benzina.torch.operations.ConstantWarpTransform(warp=(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))[source]

Represents a constant warp transformation to be applied on each sample of a batch independently of its index.

Parameters:warp (iterable of numerics, optional) – a flatten, row-major 3 x 3 warp matrix (default: flatten identity matrix).
class benzina.torch.operations.ConstantNormTransform(norm=(1.0, 1.0, 1.0))[source]

Represents a constant norm transformation to be applied on each sample of a batch independently of its index.

Parameters:norm (numeric or iterable of numerics, optional) – an iterable in RGB order containing the normalization constant of a sample’s RGB channels. Components will be multiplied to the respective channels of a sample (default: (1.0, 1.0, 1.0)).
class benzina.torch.operations.ConstantBiasTransform(bias=(0.0, 0.0, 0.0))[source]

Represents a constant bias transformation to be applied on each sample of a batch independently of its index.

Parameters:bias (numeric or iterable of numerics, optional) – an iterable in RGB order containing the bias of a sample’s RGB channels. Components will be substracted to the respective channels of a sample (default: (0.0, 0.0, 0.0)).
class benzina.torch.operations.SimilarityTransform(scale=(1.0, 1.0), rotation=(-0.0, 0.0), translation_x=(0, 0), translation_y=(0, 0), flip_h=0.0, flip_v=0.0, autoscale=False)[source]

Represents a random similarity warp transformation to be applied on each sample of a batch.

Parameters:
  • scale (numeric or iterable of numerics, optional) – the scale range to draw a random value from. If a single numeric, the value and it’s inverse will be used to define the range (default: (+1.0,+1.0)).
  • rotation (iterable of numerics, optional) – the rotation range in radian to draw a random value from. If a single numeric, the value and it’s inverse will be used to define the range (default: (-0.0,+0.0)).
  • translation_x (iterable of numerics, optional) – the translation on the x axis range to draw a random value from. If a single numeric, the value and it’s inverse will be used to define the range (default: (-0,+0)).
  • translation_y (iterable of numerics, optional) – the translation on the y axis range to draw a random value from. If a single numeric, the value and it’s inverse will be used to define the range (default: (-0,+0)).
  • flip_h (iterable of numerics, optional) – the horizontal flip probability range. Valid values are between 0 and 1 (default: (0.0)).
  • flip_v (iterable of numerics, optional) – the vertical flip probability range. Valid values are between 0 and 1 (default: (0.0)).
  • autoscale (bool, optional) – If True, the sample will be automatically scaled to the output shape before applying the other transformations (default: False).