API

benzina.torch.dataloader

benzina.torch.dataset

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), ratio=None, degrees=(-0.0, 0.0), translate=(0.0, 0.0), flip_h=0.0, flip_v=0.0, resize=False, keep_ratio=False, random_crop=False)[source]

Similarity warp transformation of the image keeping center invariant.

A crop of random size, aspect ratio and location is made. This crop can then be flipped and/or rotated to finally be resized to output size.

Parameters:
  • scale (Sequence or float or int, optional) – crop area scaling factor interval, e.g (a, b), then scale is randomly sampled from the range a <= scale <= b. If scale is a number instead of sequence, the range of scale will be (scale^-1, scale). (default: (+1.0, +1.0))
  • ratio (Sequence or float or int, optional) – range of crop aspect ratio. If ratio is a number instead of sequence like (min, max), the range of aspect ratio will be (ratio^-1, ratio). Will keep original aspect ratio by default.
  • degrees (Sequence or float or int, optional) – range of degrees to select from. If degrees is a number instead of sequence like (min, max), the range of degrees will be (-degrees, +degrees). (default: (-0.0, +0.0))
  • translate (Sequence or float or int, optional) – sequence of maximum absolute fraction for horizontal and vertical translations. For example translate=(a, b), then horizontal shift is randomly sampled in the range -output_width * a < dx < output_width * a and vertical shift is randomly sampled in the range -output_height * b < dy < output_height * b. If translate is a number instead of sequence, translate will be (translate, translate). These translations are applied independently from random_crop. (default: (0.0, 0.0))
  • flip_h (bool, optional) – probability of the image being flipped horizontally. (default: +0.0)
  • flip_v (bool, optional) – probability of the image being flipped vertically. (default: +0.0)
  • resize (bool, optional) – resize the cropped image to fit the output size. It is forced to True if scale or ratio are specified. (default: False)
  • keep_ratio (bool, optional) – match the smaller edge to the corresponding output edge size, keeping the aspect ratio after resize. Has no effect if resize is False. (default: False)
  • random_crop (bool, optional) – randomly crop the image instead of a center crop. (default: False)
class benzina.torch.operations.RandomResizedCrop(scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333))[source]

Crop to random size, aspect ratio and location.

A crop of random size, aspect ratio and location is made. This crop is finally resized to output size.

This is popularly used to train the Inception networks.

Parameters:
  • scale (Sequence or float or int, optional) – crop area scaling factor interval, e.g (a, b), then scale is randomly sampled from the range a <= scale <= b. If scale is a number instead of sequence, the range of scale will be (scale^-1, scale). (default: (+0.08, +1.0))
  • ratio (Sequence or float or int, optional) – range of crop aspect ratio. If ratio is a number instead of sequence like (min, max), the range of aspect ratio will be (ratio^-1, ratio). Will keep original aspect ratio by default. (default: (3./4., 4./3.))
class benzina.torch.operations.CenterResizedCrop(scale=1.0, keep_ratio=True)[source]

Crops at the center and resize.

A crop at the center is made then resized to the output size.

Parameters:
  • scale (float or int, optional) – edges scaling factor. (default: +1.0)
  • keep_ratio (bool, optional) – match the smaller edge to the corresponding output edge size, keeping the aspect ratio after resize. (default: False)
benzina.torch.operations.compute_affine_matrix(in_shape, out_shape, crop=None, degrees=0.0, translate=(0.0, 0.0), flip_h=False, flip_v=False, resize=False, keep_ratio=False)[source]

Similarity warp transformation of the image keeping center invariant.

Parameters:
  • in_shape (Sequence) – the shape of the input image
  • out_shape (Sequence) – the shape of the output image
  • crop (Sequence, optional) – crop center location, width and height. The center location is relative to the center of the image. If resize is not True, crop is simply a translation in the in_shape space.
  • degrees (float or int, optional) – degrees to rotate the crop. (default: (0.0))
  • translate (Sequence, optional) – horizontal and vertical translations. (default: (0.0, 0.0))
  • flip_h (bool, optional) – flip the image horizontally. (default: False)
  • flip_v (bool, optional) – flip the image vertically. (default: False)
  • resize (bool, optional) – resize the cropped image to fit the output’s size. (default: False)
  • keep_ratio (bool, optional) – match the smaller edge to the corresponding output edge size, keeping the aspect ratio after resize. Has no effect if resize is False. (default: False)