inferno.io.transform package

Submodules

inferno.io.transform.base module

class inferno.io.transform.base.Compose(*transforms)[source]

Bases: object

Composes multiple callables (including but not limited to Transform objects).

add(transform)[source]
remove(name)[source]
class inferno.io.transform.base.DTypeMapping[source]

Bases: object

DTYPE_MAPPING = {'byte': 'uint8', 'double': 'float64', 'float': 'float32', 'float16': 'float16', 'float32': 'float32', 'float64': 'float64', 'half': 'float16', 'int': 'int32', 'int32': 'int32', 'int64': 'int64', 'long': 'int64', 'uint8': 'uint8'}
class inferno.io.transform.base.Transform(apply_to=None)[source]

Bases: object

Base class for a Transform. The argument apply_to (list) specifies the indices of the tensors this transform will be applied to.

The following methods are recognized (in order of descending priority):
  • batch_function: Applies to all tensors in a batch simultaneously
  • tensor_function: Applies to just __one__ tensor at a time.
  • volume_function: For 3D volumes, applies to just __one__ volume at a time.
  • image_function: For 2D or 3D volumes, applies to just __one__ image at a time.

For example, if both volume_function and image_function are defined, this means that only the former will be called. If the inputs are therefore not 5D batch-tensors of 3D volumes, a NotImplementedError is raised.

build_random_variables(**kwargs)[source]
clear_random_variables()[source]
get_random_variable(key, default=None, build=True, **random_variable_building_kwargs)[source]
set_random_variable(key, value)[source]

inferno.io.transform.generic module

class inferno.io.transform.generic.AsTorchBatch(dimensionality, add_channel_axis_if_necessary=True, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Converts a given numpy array to a torch batch tensor.

The result is a torch tensor __without__ the leading batch axis. For example, if the input is an image of shape (100, 100), the output is a batch of shape (1, 100, 100). The collate function will add the leading batch axis to obtain a tensor of shape (N, 1, 100, 100), where N is the batch-size.

tensor_function(tensor)[source]
class inferno.io.transform.generic.Cast(dtype='float', **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform, inferno.io.transform.base.DTypeMapping

Casts inputs to a specified datatype.

tensor_function(tensor)[source]
class inferno.io.transform.generic.Label2OneHot(num_classes, dtype='float', **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform, inferno.io.transform.base.DTypeMapping

Convert integer labels to one-hot vectors for arbitrary dimensional data.

tensor_function(tensor)[source]
class inferno.io.transform.generic.Normalize(eps=0.0001, mean=None, std=None, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Normalizes input to zero mean unit variance.

tensor_function(tensor)[source]
class inferno.io.transform.generic.NormalizeRange(normalize_by=255.0, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Normalizes input by a constant.

tensor_function(tensor)[source]
class inferno.io.transform.generic.Project(projection, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Given a projection mapping (i.e. a dict) and an input tensor, this transform replaces all values in the tensor that equal a key in the mapping with the value corresponding to the key.

tensor_function(tensor)[source]

inferno.io.transform.image module

class inferno.io.transform.image.AdditiveGaussianNoise(sigma, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Add gaussian noise to the input.

build_random_variables(**kwargs)[source]
image_function(image)[source]
class inferno.io.transform.image.BinaryDilation(num_iterations=1, morphology_kwargs=None, **super_kwargs)[source]

Bases: inferno.io.transform.image.BinaryMorphology

Apply a binary dilation operation on an image.

class inferno.io.transform.image.BinaryErosion(num_iterations=1, morphology_kwargs=None, **super_kwargs)[source]

Bases: inferno.io.transform.image.BinaryMorphology

Apply a binary erosion operation on an image.

class inferno.io.transform.image.BinaryMorphology(mode, num_iterations=1, morphology_kwargs=None, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Apply a binary morphology operation on an image. Supported operations are dilation and erosion.

image_function(image)[source]
class inferno.io.transform.image.CenterCrop(size, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Crop patch of size size from the center of the image

image_function(image)[source]
class inferno.io.transform.image.ElasticTransform(alpha, sigma, order=1, invert=False, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Random Elastic Transformation.

NATIVE_DTYPES = {'float64', 'float32'}
PREFERRED_DTYPE = 'float32'
build_random_variables(**kwargs)[source]
cast(image)[source]
image_function(image)[source]
uncast(image)[source]
class inferno.io.transform.image.PILImage2NumPyArray(apply_to=None)[source]

Bases: inferno.io.transform.base.Transform

Convert a PIL Image object to a numpy array.

For images with multiple channels (say RGB), the channel axis is moved to front. Therefore, a (100, 100, 3) RGB image becomes an array of shape (3, 100, 100).

tensor_function(tensor)[source]
class inferno.io.transform.image.RandomCrop(output_image_shape, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Crop input to a given size.

This is similar to torchvision.transforms.RandomCrop, except that it operates on numpy arrays instead of PIL images. If you do have a PIL image and wish to use this transform, consider applying PILImage2NumPyArray first.

Warning

If output_image_shape is larger than the image itself, the image is not cropped (along the relevant dimensions).

build_random_variables(height_leeway, width_leeway)[source]
clear_random_variables()[source]
image_function(image)[source]
class inferno.io.transform.image.RandomFlip(allow_lr_flips=True, allow_ud_flips=True, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Random left-right or up-down flips.

build_random_variables(**kwargs)[source]
image_function(image)[source]
class inferno.io.transform.image.RandomGammaCorrection(gamma_between=(0.5, 2.0), gain=1, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Applies gamma correction [1] with a random gamma.

This transform uses skimage.exposure.adjust_gamma, which requires the input be positive.

References

[1] https://en.wikipedia.org/wiki/Gamma_correction

build_random_variables()[source]
image_function(image)[source]
class inferno.io.transform.image.RandomRotate(**super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Random 90-degree rotations.

build_random_variables(**kwargs)[source]
image_function(image)[source]
class inferno.io.transform.image.RandomSizedCrop(ratio_between=None, height_ratio_between=None, width_ratio_between=None, preserve_aspect_ratio=False, relative_target_aspect_ratio=None, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Extract a randomly sized crop from the image.

The ratio of the sizes of the cropped and the original image can be limited within specified bounds along both axes. To resize back to a constant sized image, compose with Scale.

build_random_variables(image_shape)[source]
image_function(image)[source]
class inferno.io.transform.image.RandomTranspose(**super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Random 2d transpose.

build_random_variables(**kwargs)[source]
image_function(image)[source]
class inferno.io.transform.image.Scale(output_image_shape, interpolation_order=3, zoom_kwargs=None, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Scales an image to a given size with spline interpolation of requested order.

Unlike torchvision.transforms.Scale, this does not depend on PIL and therefore works with numpy arrays. If you do have a PIL image and wish to use this transform, consider applying PILImage2NumPyArray first.

Warning

This transform uses scipy.ndimage.zoom and requires scipy >= 0.13.0 to work correctly.

image_function(image)[source]

inferno.io.transform.volume module

class inferno.io.transform.volume.CentralSlice(apply_to=None)[source]

Bases: inferno.io.transform.base.Transform

volume_function(volume)[source]
class inferno.io.transform.volume.RandomFlip3D(**super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

build_random_variables(**kwargs)[source]
volume_function(volume)[source]
class inferno.io.transform.volume.VolumeAsymmetricCrop(crop_left, crop_right, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Crop crop_left from the left borders and crop_right from the right borders

volume_function(volume)[source]
class inferno.io.transform.volume.VolumeCenterCrop(size, **super_kwargs)[source]

Bases: inferno.io.transform.base.Transform

Crop patch of size size from the center of the volume

volume_function(volume)[source]

Module contents