Image data augmentation Keras M1 Mac

Hi there,

I am trying to augment some image data in TensorFlow. I am running TensorFlow-macos version 2.6.0 and Tensorflow-metal version 0.2.0.

When I run the following lines of code:

data_augmentation = keras.Sequential( [ layers.RandomFlip("horizontal"), layers.RandomRotation(0.1), layers.RandomZoom(0.2), ] )

for images, _ in train_dataset.take(1):
for i in range(9): augmented_images = data_augmentation(images)

I get the following error message:

NotFoundError: No registered 'RngReadAndSkip' OpKernel for 'GPU' devices compatible with node {{node RngReadAndSkip}} . Registered: device='XLA_CPU_JIT' device='CPU' [Op:RngReadAndSkip]

I have searched the internet extensively for a workaround, however have not found one. Any help would be greatly appreciated.

Edie

Hi @Edie_Bishop,

Thanks for reporting this issue. The RngReadAndSkip Op has not yet been added to the tensorflow-metal plugin hence the error. We are taking a look into this, I'll add an update here once this is resolved.

In the meanwhile the workaround would be to try and run the portion of the code requiring this op inside a block that uses the CPU explicitly with

with tf.device('/cpu:0'):
    #Your code here

Same issue. This code is part of Francois Chollet's book, "Deep Learning with Python" so I expect many are having this issue.

The suggested solution does not work, either when I wrap the whole Jupyter cell in the with tf.device statement or when I wrap the specific line "augmented_images = data_augmentation(images)" in the tf.device statement.

This code segment is a prerequisite for further exercises in a later chapter, which amplifies the desire for a solution.

Thanks, Brett

Please use Tensor Flow TensorFlow Version 2.7.0 As mentioned by Frameworks Engineer & chaitanya_ambaruk, please use the with tf.device('/CPU:0'):

PS: Need to place this piece of code in the correct line of code. For the above example please place it before you start the augmentation process

with tf.device('/CPU:0'):
    data_augmentation = keras.Sequential(
    [
     layers.experimental.preprocessing.RandomFlip("horizontal_and_vertical", input_shape = (img_height, img_width,3)),
     layers.experimental.preprocessing.RandomRotation(0.2),
     layers.experimental.preprocessing.RandomZoom(0.2)
    ]
)

plt.figure(figsize=(10,10))
for images, _ in train_ds.take(5):
  for i in range(9):
    augmented_images = data_augmentation(images)
    ax = plt.subplot(3,3,i+1)
    plt.imshow(augmented_images[0].numpy().astype('uint8'))
    plt.axis("off");

Work fine for me, with with this function "layers.experimental.preprocessing":

tf.device('/cpu:0'): data_augmentation = keras.Sequential( [ layers.experimental.preprocessing.RandomFlip("horizontal"), layers.experimental.preprocessing.RandomRotation(0.05), ] )

RngReadAndSkip is registered on the GPU in tensorflow-metal==0.5.1.

I have the same issue with layers.RandomZoom(0.2). I used the "with tf.device..." and it didnt work for me...

Image data augmentation Keras M1 Mac
 
 
Q