Apply customized augmentations using tensorflow object detection api

Hello,

I’m quite new to tensorflow and I was trying to train an object detector using their api. I was wondering if there is a way to pass customized augmentations in the .config file or include them in some other way in the preprocessing step.

For example, I noticed their api does not implement image blur and noise. What I would like to do in this case is to pass something like the following in the .config file:

data_augmentation_options{
   my_own_augmentation{
     my_augmentation_parameters
   }
}

Where my_own_augmentation is a function implementing, in this case, image blur and noise. As an alternative, it would be also fine to include it dynamically in my python code.

I have been looking online for a while, but the few solutions I have found consist of changing tensorflow’s source code, which to me seems a really bad coding practice.

I hope the question is clear. Thank you in advance for the help!

Hi @vfanizza ,

TensorFlow provides a flexible data augmentation library called tf.data.experimental.augment that you can leverage within your training pipeline. This library allows defining custom augmentations using Python functions. Here’s an example demonstrating how to implement your desired blur and noise augmentation:

  # Apply blur
  image = tf.image.gaussian_blur(image, kernel_size=[3, 3], sigma=your_blur_parameter)
  # Add noise
  noise = tf.random.normal(shape=tf.shape(image), mean=0.0, stddev=your_noise_parameter)
  image = image + noise
  return image

# Add your custom augmentation to the training pipeline

dataset = dataset.map(my_augmentation)

You can then integrate this function into your TensorFlow Object Detection API pipeline by adding it to the train_config.config file within the data_augmentation_options section

Thanks.