{
  "id": 200413,
  "title": "Keras Augmentation Layers not working with TPU and Tf version 2.3.1 not available for TPU ",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/200413",
  "author_name": "",
  "post_date": "2020-11-30T12:37:40.380574900Z",
  "votes": 3,
  "comment_count": 1,
  "views": 0,
  "content": "<p>While experimenting with Keras preprocessing and Augmentation Layers I come across this error:</p>\n<p><code>AttributeError: module 'tensorflow.keras.layers.experimental.preprocessing' has no attribute 'RandomZoom'\n</code></p>\n<p>Tensorflow Version 2.2.0</p>\n<h4>[NOTE] - At first I thought the above error is because of the version so I tried to upgrade TensorFlow to the latest version but on importing, it is showing me version <code>2.2.0</code> instead of <code>2.3.1</code> while <code>2.3.1</code> is available in case of GPU and normal notebooks (without any accelerators) but inside TPU notebooks we are provided with <code>tf 2.2.0</code></h4>\n<p>You can check <a href=\"https://keras.io/api/layers/preprocessing_layers/image_preprocessing/\" target=\"_blank\">here</a> the available preprocessing layers in latest Keras version. </p>\n<p>Except <code>RandomZoom</code> every other operation was available so I commented it out and move on with other augmentation but to my surprise, those augmentations were not working see below - </p>\n<h1>TPU</h1>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F77fde7d4dec355b28dc7eaddeb00447a%2FScreenshot%20(156).png?generation=1606738032420772&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F155bc22d3aa00f7cceb9f4830bc27188%2FScreenshot%20(158).png?generation=1606738079220316&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F7dab6f43d5179abaf305a0daff4d6bdb%2FScreenshot%20(157).png?generation=1606738057273997&amp;alt=media\" alt=\"\"></p>\n<p>Even after applying augmentations layers, the augmentations weren't working. While using GPU as accelerator it worked </p>\n<h1>GPU</h1>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F5adf2044aa48015a398c29463ce22ebf%2FScreenshot%20(161).png?generation=1606738381395465&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F665a3c63a344d8dc6ad0175f90ded9a2%2FScreenshot%20(159).png?generation=1606738444966207&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2Fde247ebc9d43deb373f871870c167aaf%2FScreenshot%20(160).png?generation=1606738398362754&amp;alt=media\" alt=\"\"></p>\n<p>Augmentation layers are working in case of GPU. </p>\n<p>Possible Reasons - </p>\n<ul>\n<li><p>Maybe some issue with TensorFlow version. I tried to upgrade to the latest version of TensorFlow but while importing it was showing the older Tensorflow version. </p></li>\n<li><p>Keras Augmentation Layers are not working with TPU.</p></li>\n</ul>\n<p>If anyone who is using Keras Tensorflow can confirm this too would be very helpful for others as well.</p>\n<p>Is there any way to upgrade tf version to <code>2.3.1</code> in TPU notebooks?</p>",
  "messages": [
    {
      "id": "1096346",
      "postDate": "11/30/2020 12:37:40",
      "content": "<p>While experimenting with Keras preprocessing and Augmentation Layers I come across this error:</p>\n<p><code>AttributeError: module 'tensorflow.keras.layers.experimental.preprocessing' has no attribute 'RandomZoom'\n</code></p>\n<p>Tensorflow Version 2.2.0</p>\n<h4>[NOTE] - At first I thought the above error is because of the version so I tried to upgrade TensorFlow to the latest version but on importing, it is showing me version <code>2.2.0</code> instead of <code>2.3.1</code> while <code>2.3.1</code> is available in case of GPU and normal notebooks (without any accelerators) but inside TPU notebooks we are provided with <code>tf 2.2.0</code></h4>\n<p>You can check <a href=\"https://keras.io/api/layers/preprocessing_layers/image_preprocessing/\" target=\"_blank\">here</a> the available preprocessing layers in latest Keras version. </p>\n<p>Except <code>RandomZoom</code> every other operation was available so I commented it out and move on with other augmentation but to my surprise, those augmentations were not working see below - </p>\n<h1>TPU</h1>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F77fde7d4dec355b28dc7eaddeb00447a%2FScreenshot%20(156).png?generation=1606738032420772&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F155bc22d3aa00f7cceb9f4830bc27188%2FScreenshot%20(158).png?generation=1606738079220316&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F7dab6f43d5179abaf305a0daff4d6bdb%2FScreenshot%20(157).png?generation=1606738057273997&amp;alt=media\" alt=\"\"></p>\n<p>Even after applying augmentations layers, the augmentations weren't working. While using GPU as accelerator it worked </p>\n<h1>GPU</h1>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F5adf2044aa48015a398c29463ce22ebf%2FScreenshot%20(161).png?generation=1606738381395465&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F665a3c63a344d8dc6ad0175f90ded9a2%2FScreenshot%20(159).png?generation=1606738444966207&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2Fde247ebc9d43deb373f871870c167aaf%2FScreenshot%20(160).png?generation=1606738398362754&amp;alt=media\" alt=\"\"></p>\n<p>Augmentation layers are working in case of GPU. </p>\n<p>Possible Reasons - </p>\n<ul>\n<li><p>Maybe some issue with TensorFlow version. I tried to upgrade to the latest version of TensorFlow but while importing it was showing the older Tensorflow version. </p></li>\n<li><p>Keras Augmentation Layers are not working with TPU.</p></li>\n</ul>\n<p>If anyone who is using Keras Tensorflow can confirm this too would be very helpful for others as well.</p>\n<p>Is there any way to upgrade tf version to <code>2.3.1</code> in TPU notebooks?</p>",
      "rawMarkdown": "While experimenting with Keras preprocessing and Augmentation Layers I come across this error:\n\n`AttributeError: module 'tensorflow.keras.layers.experimental.preprocessing' has no attribute 'RandomZoom'\n`\n\nTensorflow Version 2.2.0\n\n#### [NOTE] - At first I thought the above error is because of the version so I tried to upgrade TensorFlow to the latest version but on importing, it is showing me version `2.2.0` instead of `2.3.1` while `2.3.1` is available in case of GPU and normal notebooks (without any accelerators) but inside TPU notebooks we are provided with `tf 2.2.0`\n\nYou can check [here](https://keras.io/api/layers/preprocessing_layers/image_preprocessing/) the available preprocessing layers in latest Keras version. \n\nExcept `RandomZoom` every other operation was available so I commented it out and move on with other augmentation but to my surprise, those augmentations were not working see below - \n\n# TPU\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F77fde7d4dec355b28dc7eaddeb00447a%2FScreenshot%20(156).png?generation=1606738032420772&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F155bc22d3aa00f7cceb9f4830bc27188%2FScreenshot%20(158).png?generation=1606738079220316&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F7dab6f43d5179abaf305a0daff4d6bdb%2FScreenshot%20(157).png?generation=1606738057273997&alt=media)\n\nEven after applying augmentations layers, the augmentations weren't working. While using GPU as accelerator it worked \n\n# GPU\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F5adf2044aa48015a398c29463ce22ebf%2FScreenshot%20(161).png?generation=1606738381395465&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F665a3c63a344d8dc6ad0175f90ded9a2%2FScreenshot%20(159).png?generation=1606738444966207&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2Fde247ebc9d43deb373f871870c167aaf%2FScreenshot%20(160).png?generation=1606738398362754&alt=media)\n\nAugmentation layers are working in case of GPU. \n\nPossible Reasons - \n\n- Maybe some issue with TensorFlow version. I tried to upgrade to the latest version of TensorFlow but while importing it was showing the older Tensorflow version. \n\n- Keras Augmentation Layers are not working with TPU.\n\nIf anyone who is using Keras Tensorflow can confirm this too would be very helpful for others as well.\n\nIs there any way to upgrade tf version to `2.3.1` in TPU notebooks?",
      "votes": null
    },
    {
      "id": "1169456",
      "postDate": "01/25/2021 14:02:27",
      "content": "<p>The Keras \"Random\" preprocessing layers do not work on TPU. This is a known bug: <a href=\"https://github.com/tensorflow/tensorflow/issues/42454\" target=\"_blank\">GitHub Issue</a>. Currently, it seems better not to use them, they are still experimental.</p>",
      "rawMarkdown": "The Keras \"Random\" preprocessing layers do not work on TPU. This is a known bug: [GitHub Issue](https://github.com/tensorflow/tensorflow/issues/42454). Currently, it seems better not to use them, they are still experimental.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1169456,
      "author_name": "friedchips",
      "author_url": "",
      "post_date": "01/25/2021 14:02:27",
      "content": "<p>The Keras \"Random\" preprocessing layers do not work on TPU. This is a known bug: <a href=\"https://github.com/tensorflow/tensorflow/issues/42454\" target=\"_blank\">GitHub Issue</a>. Currently, it seems better not to use them, they are still experimental.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1096346": "While experimenting with Keras preprocessing and Augmentation Layers I come across this error:\n\n`AttributeError: module 'tensorflow.keras.layers.experimental.preprocessing' has no attribute 'RandomZoom'\n`\n\nTensorflow Version 2.2.0\n\n#### [NOTE] - At first I thought the above error is because of the version so I tried to upgrade TensorFlow to the latest version but on importing, it is showing me version `2.2.0` instead of `2.3.1` while `2.3.1` is available in case of GPU and normal notebooks (without any accelerators) but inside TPU notebooks we are provided with `tf 2.2.0`\n\nYou can check [here](https://keras.io/api/layers/preprocessing_layers/image_preprocessing/) the available preprocessing layers in latest Keras version. \n\nExcept `RandomZoom` every other operation was available so I commented it out and move on with other augmentation but to my surprise, those augmentations were not working see below - \n\n# TPU\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F77fde7d4dec355b28dc7eaddeb00447a%2FScreenshot%20(156).png?generation=1606738032420772&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F155bc22d3aa00f7cceb9f4830bc27188%2FScreenshot%20(158).png?generation=1606738079220316&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F7dab6f43d5179abaf305a0daff4d6bdb%2FScreenshot%20(157).png?generation=1606738057273997&alt=media)\n\nEven after applying augmentations layers, the augmentations weren't working. While using GPU as accelerator it worked \n\n# GPU\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F5adf2044aa48015a398c29463ce22ebf%2FScreenshot%20(161).png?generation=1606738381395465&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2F665a3c63a344d8dc6ad0175f90ded9a2%2FScreenshot%20(159).png?generation=1606738444966207&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2167036%2Fde247ebc9d43deb373f871870c167aaf%2FScreenshot%20(160).png?generation=1606738398362754&alt=media)\n\nAugmentation layers are working in case of GPU. \n\nPossible Reasons - \n\n- Maybe some issue with TensorFlow version. I tried to upgrade to the latest version of TensorFlow but while importing it was showing the older Tensorflow version. \n\n- Keras Augmentation Layers are not working with TPU.\n\nIf anyone who is using Keras Tensorflow can confirm this too would be very helpful for others as well.\n\nIs there any way to upgrade tf version to `2.3.1` in TPU notebooks?",
    "1169456": "The Keras \"Random\" preprocessing layers do not work on TPU. This is a known bug: [GitHub Issue](https://github.com/tensorflow/tensorflow/issues/42454). Currently, it seems better not to use them, they are still experimental."
  },
  "source": "meta"
}