API - Utils

Augmentation

augmentation.blend(images_2, factors, value_range=None)

Blend image1 and image2 using β€˜factors’. Can be batched inputs.

Factor can be above 0.0. A value of 0.0 means only image1 is used. A value of 1.0 means only image2 is used. A value between 0.0 and 1.0 means we linearly interpolate the pixel values between the two images. A value greater than 1.0 β€œextrapolates” the difference between the two pixel values. If value_range is set, the results will be clipped into value_range

Parameters:
  • image1 (tf.Tensor) – First image(s).

  • image2 (tf.Tensor) – Second image(s).

  • factor (float|tf.Tensor) – The blend factor(s).

  • value_range (Sequence[int|float], optional) – The value range of the results. Defaults to None.

References

augmentation.rgb_to_grayscale()

Converts images from RGB to Grayscale.

Compared to tf.image.rgb_to_grayscale, this function replaces tf.tensordot with tf.math.multiply and tf.math.add to reduce memory usage.

Parameters:

images (tf.Tensor) – The RGB tensor to convert. The last dimension must have size 3 and should contain RGB values.

References

augmentation.get_rotation_matrix(image_height, image_width, to_square=False, name=None)

Returns projective transforms for the given angles.

Parameters:
  • angles (tf.Tensor) – a vector with the angles to rotate each image in the batch.

  • image_height (tf.Tensor) – Height of the images to be transformed.

  • image_width (tf.Tensor) – Width of the images to be transformed.

  • to_square (bool, optional) – Whether to append ones to last dimension and reshape to (batch_size, 3, 3). Defaults to False.

  • name (str, optional) – The name of the op. Defaults to None.

References

augmentation.get_translation_matrix(image_height, image_width, to_square=False, name=None)

Returns projective transforms for the given translations.

Parameters:
  • translations (tf.Tensor) – A matrix of 2-element lists representing [dx, dy] to translate for a batch of images.

  • image_height (tf.Tensor) – Height of the images to be transformed.

  • image_width (tf.Tensor) – Width of the images to be transformed.

  • to_square (bool, optional) – Whether to append ones to last dimension and reshape to (batch_size, 3, 3). Defaults to False.

  • name (str, optional) – The name of the op. Defaults to None.

References

augmentation.get_zoom_matrix(image_height, image_width, to_square=False, name=None)

Returns projective transforms for the given zooms.

Parameters:
  • zooms (tf.Tensor) – A matrix of 2-element lists representing [zx, zy] to zoom for a batch of images.

  • image_height (tf.Tensor) – Height of the images to be transformed.

  • image_width (tf.Tensor) – Width of the images to be transformed.

  • to_square (bool, optional) – Whether to append ones to last dimension and reshape to (batch_size, 3, 3). Defaults to False.

  • name (str, optional) – The name of the op. Defaults to None.

References

augmentation.get_shear_matrix(to_square=False, name=None)

Returns projective transforms for the given shears.

Parameters:
  • shears (tf.Tensor) – A matrix of 2-element lists representing [sx, sy] to shear for a batch of images.

  • to_square (bool, optional) – Whether to append ones to last dimension and reshape to (batch_size, 3, 3). Defaults to False.

  • name (str, optional) – The name of the op. Defaults to None.

References

augmentation.is_factor_working(not_working_value=0.0)

Check whether factor is working or not.

Parameters:
  • factor (int|float|Sequence[int|float]|keras_aug.FactorSampler) – The factor to check whether it is working or not.

  • not_working_value (float, optional) – The value indicating not working status. Defaults to 0.0.

augmentation.get_images_shape(dtype=tf.int32)

Get heights and widths of the input images.

Input images can be tf.Tensor or tf.RaggedTensor with the shape of [B, H|None, W|None, C].

Parameters:
  • images (tf.Tensor|tf.RaggedTensor) – The input images.

  • dtype (tf.dtypes.DType, optional) – The dtype of the outputs. Defaults to tf.int32.

Bounding Box

bounding_box.sanitize_bounding_boxes(min_size=None, min_area_ratio=None, max_aspect_ratio=None, bounding_box_format=None, reference_bounding_boxes=None, images=None, reference_images=None)

Sanitize bounding boxes by min_size, min_area_ratio and max_aspect_ratio.

Parameters:
  • bounding_boxes (dict[str, tf.Tensor]) – The bounding boxes to sanitize.

  • min_size (float, optional) – The minimum size of the bounding boxes.

  • min_area_ratio (float, optional) – The minimum area ratio of original bounding boxes to bounding boxes for sanitizing. Defaults to None.

  • max_aspect_ratio (float, optional) – The maximum aspect ratio of bounding boxes for sanitizing. Defaults to None.

  • bounding_box_format (str, optional) – The format of bounding boxes of input dataset. Refer https://github.com/keras-team/keras-cv/blob/master/keras_cv/bounding_box/converters.py for more details on supported bounding box formats.

  • reference_bounding_boxes (dict[str, tf.Tensor], optional) – The reference bounding boxes when apply sanitizing with min_area_ratio enabled. Defaults to None.

  • images (tf.Tensor, optional) – The images for bounding boxes format conversion.

  • reference_images (tf.Tensor, optional) – The reference images for reference bounding boxes format conversion.

References