Tensorflow image random_ There seems to be something wrong with the shift function

Environment: Python 3.6, TensorFlow 1.15
Hope for augmentation, using tf keras. Preprocessing. Image. Random_shift function
Unsupported operand type(s) for *: ‘Dimension’ and ‘float’
Line 446 in tensor_shape.py is return self * other
Return self * other –> return self * other –> return self * int(other)
The random_shift function does not work, and the image does not have any shift effects
As a last resort, change the design function to achieve random_shift function function
According to my requirements, first of all, two random numbers are generated by TF.Random. Uniform, which are used as the translation pixels of the width and height dimensions of the image. Then use tf.roll to translate the image in two dimensions of height and width. The code is as follows:

shift_num = tf.random.uniform(shape=[2], minval=-img_height/2, maxval=img_height/2, dtype=tf.dtype.int32)

img_out = tf.roll(img_in, shift=shift_num, axis=[1,2])

This code does what I need the random_shift function to do, but it’s slow
over


Read More: