ma7555
ma7555

Reputation: 400

Create image augmentations with tf.data.Dataset to produce different augmentations with every epoch

I have a dataset fetched from tfds, I want to create normal random rotates on the images that would change with every epoch

This is the current pipeline i use where should i place the .map(random_rotate) in this pipeline to make the augmentations change with every epoch

ds_train = ds_train.map(scale, num_parallel_calls=AUTOTUNE).cache().shuffle(ds_info.splits['train'].num_examples).batch(batch_size).prefetch(AUTOTUNE).repeat()

Upvotes: 1

Views: 591

Answers (1)

Richard X
Richard X

Reputation: 1134

Any random augmentation operation that you use should be placed after the cache() method of your data set. cache() will save your data and every subsequent call to the data set after one epoch will be to the cache location. That means operations that happen before the cache() will not be called again. If your rotation augmentation only works with one image at a time, place the map() after cache() but before batch(). If your rotation augmentation works with batches of images, then you can place it after batch() but before prefetch().

Upvotes: 2

Related Questions