dacapo.gp.elastic_augment_fuse

Attributes

logger

Classes

ElasticAugment

Elasticly deform a batch. Requests larger batches upstream to avoid data

Module Contents

dacapo.gp.elastic_augment_fuse.logger
class dacapo.gp.elastic_augment_fuse.ElasticAugment(control_point_spacing, control_point_displacement_sigma, rotation_interval, subsample=1, augmentation_probability=1.0, seed=None, uniform_3d_rotation=False)

Elasticly deform a batch. Requests larger batches upstream to avoid data loss due to rotation and jitter. :param control_point_spacing: Distance between control points for the elastic deformation, in voxels per dimension. :type control_point_spacing: tuple of int :param control_point_displacement_sigma: Standard deviation of control point displacement distribution, in world coordinates. :type control_point_displacement_sigma: tuple of float :param rotation_interval: Interval to randomly sample rotation angles from (0, 2PI). :type rotation_interval: tuple of two float :param subsample: Instead of creating an elastic transformation on the full resolution, create one sub-sampled by the given factor, and linearly interpolate to obtain the full resolution transformation. This can significantly speed up this node, at the expense of having visible piecewise linear deformations for large factors. Usually, a factor of 4 can safely be used without noticeable changes. However, the default is 1 (i.e., no sub-sampling). :type subsample: int :param seed: Set random state for reproducible results (tests only, do not use in production code!!) :type seed: int :param augmentation_probability: Probability to apply the augmentation. :type augmentation_probability: float :param uniform_3d_rotation: Use a uniform 3D rotation instead of a rotation around a random axis. :type uniform_3d_rotation: bool

Provides:
  • The arrays in the batch, deformed.

Requests:
  • The arrays in the batch, enlarged such that the deformed ROI fits into the enlarged input ROI.

Method:

setup: Set up the ElasticAugment node. prepare: Prepare the ElasticAugment node. process: Process the ElasticAugment node.

Notes

This node is a port of the ElasticAugment node from the original `gunpowder <

control_point_spacing
control_point_displacement_sigma
rotation_start
rotation_max_amount
subsample
augmentation_probability
uniform_3d_rotation
do_augment = False
transformations
target_rois
setup()

Set up the object by calculating the voxel size and spatial dimensions.

This method calculates the voxel size by finding the minimum value for each axis from the voxel sizes of all array specs. It then sets the voxel_size attribute of the object. The spatial dimensions are also set based on the dimensions of the voxel size.

Raises:

AssertionError – If the voxel size is not a Coordinate object.

Examples

>>> setup()
prepare(request)

Prepares the request for augmentation.

Parameters:

request – The request object containing the data to be augmented.

Raises:

AssertionError – If the key in the request is not an ArrayKey or GraphKey.

Examples

>>> prepare(request)

Notes

This method prepares the request for augmentation by performing the following steps: 1. Logs the preparation details, including the transformation voxel size. 2. Calculates the master ROI based on the total ROI. 3. Generates a uniform random sample and determines whether to perform augmentation based on the augmentation probability. 4. If augmentation is not required, logs the decision and returns. 5. Snaps the master ROI to the grid based on the voxel size and calculates the master transformation. 6. Clears the existing transformations and target ROIs. 7. Iterates over each key in the request and prepares it for augmentation. 8. Updates the upstream request with the modified ROI.

process(batch, request)

Process the ElasticAugment node.

Parameters:
  • batch – The batch object containing the data to be processed.

  • request – The request object specifying the data to be processed.

Raises:

AssertionError – If the key in the request is not an ArrayKey or GraphKey.

Examples

>>> process(batch, request)

Notes

This method applies the transformation to the data in the batch and restores the original ROIs.