Define two separate transformation functions: | |
- training data transformations that include image augmentation | |
- validation data transformations that only transpose the images, since computer vision models in 🤗 Transformers expect channels-first layout | |
import tensorflow as tf | |
def aug_transforms(image): | |
image = tf.keras.utils.img_to_array(image) | |
image = tf.image.random_brightness(image, 0.25) | |
image = tf.image.random_contrast(image, 0.5, 2.0) | |
image = tf.image.random_saturation(image, 0.75, 1.25) | |
image = tf.image.random_hue(image, 0.1) | |
image = tf.transpose(image, (2, 0, 1)) | |
return image | |
def transforms(image): | |
image = tf.keras.utils.img_to_array(image) | |
image = tf.transpose(image, (2, 0, 1)) | |
return image | |
Next, create two preprocessing functions to prepare batches of images and annotations for the model. |