I recently re-coded my input image pipeline using tf functions and tf records so that I could use TPUs (was previously using a custom tf.py_function with opencv). The problem is that I used tfa.image.transform to apply rotation and scaling augmentation, but TPUs apparently do not support the tensorflow addons package. What alternatives are there for performing image augmentation using transforms in a TPU pipeline?
Asked
Active
Viewed 653 times
1 Answers
0
I solved this issue by replacing tfa.image.transform with the following:
from tensorflow.python.keras.layers.preprocessing import image_preprocessing as image_ops
image_ops.transform()
It turns out tfa.image.transform is just a wrapper for this function. The arguments to both functions are the same.

wmcnally
- 147
- 2
- 14
-
I'm interested to know how you got this to work. I'm experiencing the same problems as [this question](https://stackoverflow.com/questions/63302446/colabtpu-not-supporting-tf-2-3-0-tf-keras-layers-experimental-preprocessing) when trying to use the keras preprocessing layers on a TPU with TF 2.3.0 (current stable version). According to [github](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/layers/preprocessing/image_preprocessing.py#L607-L684), `transform()` is a wrapper around `ImageProjectiveTransformV2()`, which doesn't appear to be supported on TPU at present. – knuckles Aug 17 '20 at 14:52
-
The transform() function is currently working for me with TF 2.3 on a v3-8. Are you using TFrecords and the tf.data api? What kind of error do you get? – wmcnally Aug 18 '20 at 15:10
-
I'm literally getting the same error as the question I linked to, and although I am not explicitly using `transform()`, I'm using layers that use the same op underneath (AFAIK). I am only using a v2-8 TPU, so I might try a v3-8 and see if that makes a difference. – knuckles Aug 19 '20 at 08:59
-
No difference between v3-8 and v2-8. I am using tfrecords and the tf.data API, but the transform is within the new keras preprocessing layers, which are part of the model. I suspect that compiling the op into a model is the problem here. Anyway, I have [opened an issue](https://github.com/tensorflow/tensorflow/issues/42454) on github and they have reproduced, so I'll stop derailing this question thread! – knuckles Aug 19 '20 at 09:18