Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

tensorflow - Data augmentation on GPU

As tf.data augmentations are executed only on CPUs. I need a way to run certain augmentations on the TPU for an audio project.
For example,

CPU: tf.recs read -> audio crop -> noise addition.
TPU: spectogram -> Mixup Augmentation.

Most augmentations can be done as a Keras Layer on top of the model, but MixUp requires both changes in input as well as label.

Is there a way to do it using tf keras APIs.

And if there is any way we can transfer part of tf.data to run on TPU that will also be helpful.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As you have rightly mentioned and as per the Tensorflow documentation also the preprocessing of tf.data is done on CPU only.
However, you can do some workaround to preprocess your tf.data using TPU/GPU by directly using transformation function in your model with something like below code.

input = tf.keras.layers.Input((512,512,3))
x = tf.keras.layers.Lambda(transform)(input) 

You can follow this Kaggle post for detailed discussion on this topic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...