{
  "id": 163909,
  "title": "Advanced hair augmentation in TensorFlow",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/163909",
  "author_name": "",
  "post_date": "2020-07-04T01:52:01.507301100Z",
  "votes": 16,
  "comment_count": 15,
  "views": 0,
  "content": "<p>I created a new notebook demonstrating how to do advanced hair augmentation in TensorFlow:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow\">SIIM: Advanced Hair Augmentation in TensorFlow</a></p>\n\n<p>This notebook is based on the idea suggested by <a href=\"https://www.kaggle.com/nroman\">Roman</a> in the following discussion topic: <a href=\"https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176\">Advanced hair augmentation</a>. Roman's code is based on the OpenCV library which works great for PyTorch users. Unfortunately, it does not work very well with TensorFlow, so if you are using tfrecords+TF then you need to rewrite the OpenCV implementation in the TensorFlow language. I am not an expert in TensorFlow but I decided to give it a try. It wasn't as easy or straightforward as I originally hoped but now it seems to be working fine. I have not tried inserting this augmentation in my training pipeline yet, so I cannot tell you if it is going to improve your score. But the idea is very cute, so it makes sense to try it. Any comments or suggestions  on how the code can be improved are very welcome! Enjoy!</p>\n\n<p>UPDATE: If you want to see how this augmentation can be included in your training pipeline take a look at Version 20 of the following public notebook of mine:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512\">EfficientNet BN+Tabular Features TF CV5 512x512</a>.</p>",
  "messages": [
    {
      "id": "914511",
      "postDate": "07/04/2020 01:52:01",
      "content": "<p>I created a new notebook demonstrating how to do advanced hair augmentation in TensorFlow:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow\">SIIM: Advanced Hair Augmentation in TensorFlow</a></p>\n\n<p>This notebook is based on the idea suggested by <a href=\"https://www.kaggle.com/nroman\">Roman</a> in the following discussion topic: <a href=\"https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176\">Advanced hair augmentation</a>. Roman's code is based on the OpenCV library which works great for PyTorch users. Unfortunately, it does not work very well with TensorFlow, so if you are using tfrecords+TF then you need to rewrite the OpenCV implementation in the TensorFlow language. I am not an expert in TensorFlow but I decided to give it a try. It wasn't as easy or straightforward as I originally hoped but now it seems to be working fine. I have not tried inserting this augmentation in my training pipeline yet, so I cannot tell you if it is going to improve your score. But the idea is very cute, so it makes sense to try it. Any comments or suggestions  on how the code can be improved are very welcome! Enjoy!</p>\n\n<p>UPDATE: If you want to see how this augmentation can be included in your training pipeline take a look at Version 20 of the following public notebook of mine:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512\">EfficientNet BN+Tabular Features TF CV5 512x512</a>.</p>",
      "rawMarkdown": "I created a new notebook demonstrating how to do advanced hair augmentation in TensorFlow:\n\n[SIIM: Advanced Hair Augmentation in TensorFlow](https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow)\n\nThis notebook is based on the idea suggested by [Roman](https://www.kaggle.com/nroman) in the following discussion topic: [Advanced hair augmentation](https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176). Roman's code is based on the OpenCV library which works great for PyTorch users. Unfortunately, it does not work very well with TensorFlow, so if you are using tfrecords+TF then you need to rewrite the OpenCV implementation in the TensorFlow language. I am not an expert in TensorFlow but I decided to give it a try. It wasn't as easy or straightforward as I originally hoped but now it seems to be working fine. I have not tried inserting this augmentation in my training pipeline yet, so I cannot tell you if it is going to improve your score. But the idea is very cute, so it makes sense to try it. Any comments or suggestions  on how the code can be improved are very welcome! Enjoy!\n\nUPDATE: If you want to see how this augmentation can be included in your training pipeline take a look at Version 20 of the following public notebook of mine:\n\n[EfficientNet BN+Tabular Features TF CV5 512x512](https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512).",
      "votes": null
    },
    {
      "id": "914552",
      "postDate": "07/04/2020 03:01:12",
      "content": "<p>Great！Thanks for sharing.</p>",
      "rawMarkdown": "Great！Thanks for sharing.",
      "votes": null
    },
    {
      "id": "914554",
      "postDate": "07/04/2020 03:07:18",
      "content": "<p>You are welcome! Hope it will help!</p>",
      "rawMarkdown": "You are welcome! Hope it will help!",
      "votes": null
    },
    {
      "id": "914906",
      "postDate": "07/04/2020 10:28:14",
      "content": "<p>great thanks for sharing</p>",
      "rawMarkdown": "great thanks for sharing",
      "votes": null
    },
    {
      "id": "915126",
      "postDate": "07/04/2020 13:45:40",
      "content": "<p>Nice! if you try it on your training pipeline, please update us about the results.</p>",
      "rawMarkdown": "Nice! if you try it on your training pipeline, please update us about the results.",
      "votes": null
    },
    {
      "id": "915290",
      "postDate": "07/04/2020 16:05:29",
      "content": "<p>This is on my to do list. Planning to get to it next week.</p>",
      "rawMarkdown": "This is on my to do list. Planning to get to it next week.",
      "votes": null
    },
    {
      "id": "915292",
      "postDate": "07/04/2020 16:06:07",
      "content": "<p>You are welcome! Happy to help!</p>",
      "rawMarkdown": "You are welcome! Happy to help!",
      "votes": null
    },
    {
      "id": "915537",
      "postDate": "07/04/2020 20:01:17",
      "content": "<p>Thanks for sharing. I tried this out, but get a error message on statements like \"h_height, h_width, _ = tf.shape(hair)\" since I am not (yet) using eager mode of execution.</p>",
      "rawMarkdown": "Thanks for sharing. I tried this out, but get a error message on statements like \"h\\_height, h\\_width, \\_ = tf.shape(hair)\" since I am not (yet) using eager mode of execution.",
      "votes": null
    },
    {
      "id": "915581",
      "postDate": "07/04/2020 22:03:04",
      "content": "<p><a href=\"/helgith\">@helgith</a> Thank you for letting me know. It will probably require some tweaking to make it work in the training pipeline -- I am planning to get to it next week.</p>\n\n<p>P.S. What version of TensorFlow are you using? I think in TensorFlow 2 eager execution should be enabled by default.</p>",
      "rawMarkdown": "helgith Thank you for letting me know. It will probably require some tweaking to make it work in the training pipeline -- I am planning to get to it next week.\n\nP.S. What version of TensorFlow are you using? I think in TensorFlow 2 eager execution should be enabled by default.",
      "votes": null
    },
    {
      "id": "915959",
      "postDate": "07/05/2020 08:40:03",
      "content": "<p>I'm using TensorFlow 2.2. I have not yet understood the error, but the message is \"OperatorNotAllowedInGraphError: iterating over <code>tf.Tensor</code> is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\"</p>",
      "rawMarkdown": "I'm using TensorFlow 2.2. I have not yet understood the error, but the message is \"OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\"",
      "votes": null
    },
    {
      "id": "916067",
      "postDate": "07/05/2020 10:25:59",
      "content": "<p>The error message seems to come from the map operation in tf.data. You should be able to reproduce it in your notebook with following coding</p>\n\n<p>`import tensorflow as tf\nAUTOTUNE = tf.data.experimental.AUTOTUNE</p>\n\n<p>def decode_image(image_path, label=None):\n    #\n    # Read and decode the image\n    bits = tf.io.read_file(image_path)\n    # dct_method='INTEGER_ACCURATE' produces the same result as OpenCV\n    img = tf.image.decode_jpeg(bits, channels=3, dct_method='INTEGER_ACCURATE') <br>\n    # Resize and crop the image\n    img=resize_and_crop_image(img) <br>\n    # Creating an augmented image\n    img_aug, n_hairs = hair_aug_tf(img)\n    # <br>\n    return image</p>\n\n<p>and now </p>\n\n<p>ds_train = (tf.data.Dataset\n                    .from_tensor_slices((train_images[0:10]))\n                    .map(decode_image, num_parallel_calls=AUTOTUNE)\n                    )`</p>\n\n<p>This gives an error message \"OperatorNotAllowedInGraphError: iterating over <code>tf.Tensor</code> is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\". (Possibly the reference to Eager execution is misleading.)</p>",
      "rawMarkdown": "The error message seems to come from the map operation in tf.data. You should be able to reproduce it in your notebook with following coding\n\n`import tensorflow as tf\nAUTOTUNE = tf.data.experimental.AUTOTUNE\n\ndef decode\\_image(image\\_path, label=None):\n    #\n    # Read and decode the image\n    bits = tf.io.read\\_file(image\\_path)\n    # dct\\_method='INTEGER\\_ACCURATE' produces the same result as OpenCV\n    img = tf.image.decode\\_jpeg(bits, channels=3, dct\\_method='INTEGER\\_ACCURATE')        \n    # Resize and crop the image\n    img=resize\\_and\\_crop_image(img)  \n    # Creating an augmented image\n    img\\_aug, n\\_hairs = hair\\_aug\\_tf(img)\n    #    \n    return image\n\nand now \n\nds_train = (tf.data.Dataset\n                    .from\\_tensor\\_slices((train\\_images[0:10]))\n                    .map(decode\\_image, num\\_parallel\\_calls=AUTOTUNE)\n                    )`\n\nThis gives an error message \"OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\". (Possibly the reference to Eager execution is misleading.)",
      "votes": null
    },
    {
      "id": "916581",
      "postDate": "07/05/2020 19:43:43",
      "content": "<p><a href=\"/helgith\">@helgith</a> Thank you for this information -- this is very helpful! I managed to reproduce the error you are referring to. It seems to be related to the peculiarities of the TensorFlow graph mode. I made a few changes in my original code and now it seems to be working in the graph mode. At least I managed to fetch a training batch and print it to the screen. I added this demo code to the very end of my notebook:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow/execution\">SIIM: Advanced Hair Augmentation in TensorFlow, Version 5</a></p>\n\n<p>Hope it helps. But please let me know if you discover any other issues. I really appreciate your feedback!</p>",
      "rawMarkdown": "helgith Thank you for this information -- this is very helpful! I managed to reproduce the error you are referring to. It seems to be related to the peculiarities of the TensorFlow graph mode. I made a few changes in my original code and now it seems to be working in the graph mode. At least I managed to fetch a training batch and print it to the screen. I added this demo code to the very end of my notebook:\n\n[SIIM: Advanced Hair Augmentation in TensorFlow, Version 5](https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow/execution)\n\nHope it helps. But please let me know if you discover any other issues. I really appreciate your feedback!",
      "votes": null
    },
    {
      "id": "917897",
      "postDate": "07/06/2020 19:37:55",
      "content": "<p><a href=\"/helgith\">@helgith</a> If you want to see how this augmentation can be included in your training pipeline take a look at Versions 17 (full) or 18 (quick) of the following public notebook of mine:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512\">EfficientNet BN+Tabular Features TF CV5 512x512</a>.</p>\n\n<p>UPDATE: Use Version 20.</p>",
      "rawMarkdown": "helgith If you want to see how this augmentation can be included in your training pipeline take a look at Versions 17 (full) or 18 (quick) of the following public notebook of mine:\n\n[EfficientNet BN+Tabular Features TF CV5 512x512](https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512).\n\nUPDATE: Use Version 20.",
      "votes": null
    },
    {
      "id": "917917",
      "postDate": "07/06/2020 19:54:39",
      "content": "<p><a href=\"/graf10a\">@graf10a</a> I had already included this and was running some test. Thanks for the changes.</p>",
      "rawMarkdown": "graf10a I had already included this and was running some test. Thanks for the changes.",
      "votes": null
    },
    {
      "id": "918093",
      "postDate": "07/07/2020 01:34:26",
      "content": "<p><a href=\"/helgith\">@helgith</a> Just wanted to let you know that I discovered an annoying bug in Versions 17 and 18 of my notebook -- because of it the augmentation was not working properly. I found out about it accidentally by printing a training batch to the screen. I tweaked the code of my augmentation function and now the bug is gone. In Version 20 of my notebook you can clearly see the augmentation performed on a training batch. So, if you decide to reference my notebook please use Version 20 -- it is the most bug-free at the moment.   </p>",
      "rawMarkdown": "helgith Just wanted to let you know that I discovered an annoying bug in Versions 17 and 18 of my notebook -- because of it the augmentation was not working properly. I found out about it accidentally by printing a training batch to the screen. I tweaked the code of my augmentation function and now the bug is gone. In Version 20 of my notebook you can clearly see the augmentation performed on a training batch. So, if you decide to reference my notebook please use Version 20 -- it is the most bug-free at the moment.",
      "votes": null
    },
    {
      "id": "918340",
      "postDate": "07/07/2020 07:35:28",
      "content": "<p><a href=\"/graf10a\">@graf10a</a> I have included the link to Version 20 in my coding.</p>",
      "rawMarkdown": "graf10a I have included the link to Version 20 in my coding.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 914552,
      "author_name": "koshirosato",
      "author_url": "",
      "post_date": "07/04/2020 03:01:12",
      "content": "<p>Great！Thanks for sharing.</p>",
      "votes": null,
      "replies": [
        {
          "id": 914554,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/04/2020 03:07:18",
          "content": "<p>You are welcome! Hope it will help!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 914906,
      "author_name": "singhakash",
      "author_url": "",
      "post_date": "07/04/2020 10:28:14",
      "content": "<p>great thanks for sharing</p>",
      "votes": null,
      "replies": [
        {
          "id": 915292,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/04/2020 16:06:07",
          "content": "<p>You are welcome! Happy to help!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 915126,
      "author_name": "dimitreoliveira",
      "author_url": "",
      "post_date": "07/04/2020 13:45:40",
      "content": "<p>Nice! if you try it on your training pipeline, please update us about the results.</p>",
      "votes": null,
      "replies": [
        {
          "id": 915290,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/04/2020 16:05:29",
          "content": "<p>This is on my to do list. Planning to get to it next week.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 915537,
      "author_name": "helgith",
      "author_url": "",
      "post_date": "07/04/2020 20:01:17",
      "content": "<p>Thanks for sharing. I tried this out, but get a error message on statements like \"h_height, h_width, _ = tf.shape(hair)\" since I am not (yet) using eager mode of execution.</p>",
      "votes": null,
      "replies": [
        {
          "id": 915581,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/04/2020 22:03:04",
          "content": "<p><a href=\"/helgith\">@helgith</a> Thank you for letting me know. It will probably require some tweaking to make it work in the training pipeline -- I am planning to get to it next week.</p>\n\n<p>P.S. What version of TensorFlow are you using? I think in TensorFlow 2 eager execution should be enabled by default.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 915959,
          "author_name": "helgith",
          "author_url": "",
          "post_date": "07/05/2020 08:40:03",
          "content": "<p>I'm using TensorFlow 2.2. I have not yet understood the error, but the message is \"OperatorNotAllowedInGraphError: iterating over <code>tf.Tensor</code> is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\"</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 916067,
          "author_name": "helgith",
          "author_url": "",
          "post_date": "07/05/2020 10:25:59",
          "content": "<p>The error message seems to come from the map operation in tf.data. You should be able to reproduce it in your notebook with following coding</p>\n\n<p>`import tensorflow as tf\nAUTOTUNE = tf.data.experimental.AUTOTUNE</p>\n\n<p>def decode_image(image_path, label=None):\n    #\n    # Read and decode the image\n    bits = tf.io.read_file(image_path)\n    # dct_method='INTEGER_ACCURATE' produces the same result as OpenCV\n    img = tf.image.decode_jpeg(bits, channels=3, dct_method='INTEGER_ACCURATE') <br>\n    # Resize and crop the image\n    img=resize_and_crop_image(img) <br>\n    # Creating an augmented image\n    img_aug, n_hairs = hair_aug_tf(img)\n    # <br>\n    return image</p>\n\n<p>and now </p>\n\n<p>ds_train = (tf.data.Dataset\n                    .from_tensor_slices((train_images[0:10]))\n                    .map(decode_image, num_parallel_calls=AUTOTUNE)\n                    )`</p>\n\n<p>This gives an error message \"OperatorNotAllowedInGraphError: iterating over <code>tf.Tensor</code> is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\". (Possibly the reference to Eager execution is misleading.)</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 916581,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/05/2020 19:43:43",
          "content": "<p><a href=\"/helgith\">@helgith</a> Thank you for this information -- this is very helpful! I managed to reproduce the error you are referring to. It seems to be related to the peculiarities of the TensorFlow graph mode. I made a few changes in my original code and now it seems to be working in the graph mode. At least I managed to fetch a training batch and print it to the screen. I added this demo code to the very end of my notebook:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow/execution\">SIIM: Advanced Hair Augmentation in TensorFlow, Version 5</a></p>\n\n<p>Hope it helps. But please let me know if you discover any other issues. I really appreciate your feedback!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 917897,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/06/2020 19:37:55",
          "content": "<p><a href=\"/helgith\">@helgith</a> If you want to see how this augmentation can be included in your training pipeline take a look at Versions 17 (full) or 18 (quick) of the following public notebook of mine:</p>\n\n<p><a href=\"https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512\">EfficientNet BN+Tabular Features TF CV5 512x512</a>.</p>\n\n<p>UPDATE: Use Version 20.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 917917,
          "author_name": "helgith",
          "author_url": "",
          "post_date": "07/06/2020 19:54:39",
          "content": "<p><a href=\"/graf10a\">@graf10a</a> I had already included this and was running some test. Thanks for the changes.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 918093,
          "author_name": "graf10a",
          "author_url": "",
          "post_date": "07/07/2020 01:34:26",
          "content": "<p><a href=\"/helgith\">@helgith</a> Just wanted to let you know that I discovered an annoying bug in Versions 17 and 18 of my notebook -- because of it the augmentation was not working properly. I found out about it accidentally by printing a training batch to the screen. I tweaked the code of my augmentation function and now the bug is gone. In Version 20 of my notebook you can clearly see the augmentation performed on a training batch. So, if you decide to reference my notebook please use Version 20 -- it is the most bug-free at the moment.   </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 918340,
          "author_name": "helgith",
          "author_url": "",
          "post_date": "07/07/2020 07:35:28",
          "content": "<p><a href=\"/graf10a\">@graf10a</a> I have included the link to Version 20 in my coding.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "914511": "I created a new notebook demonstrating how to do advanced hair augmentation in TensorFlow:\n\n[SIIM: Advanced Hair Augmentation in TensorFlow](https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow)\n\nThis notebook is based on the idea suggested by [Roman](https://www.kaggle.com/nroman) in the following discussion topic: [Advanced hair augmentation](https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176). Roman's code is based on the OpenCV library which works great for PyTorch users. Unfortunately, it does not work very well with TensorFlow, so if you are using tfrecords+TF then you need to rewrite the OpenCV implementation in the TensorFlow language. I am not an expert in TensorFlow but I decided to give it a try. It wasn't as easy or straightforward as I originally hoped but now it seems to be working fine. I have not tried inserting this augmentation in my training pipeline yet, so I cannot tell you if it is going to improve your score. But the idea is very cute, so it makes sense to try it. Any comments or suggestions  on how the code can be improved are very welcome! Enjoy!\n\nUPDATE: If you want to see how this augmentation can be included in your training pipeline take a look at Version 20 of the following public notebook of mine:\n\n[EfficientNet BN+Tabular Features TF CV5 512x512](https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512).",
    "914552": "Great！Thanks for sharing.",
    "914554": "You are welcome! Hope it will help!",
    "914906": "great thanks for sharing",
    "915126": "Nice! if you try it on your training pipeline, please update us about the results.",
    "915290": "This is on my to do list. Planning to get to it next week.",
    "915292": "You are welcome! Happy to help!",
    "915537": "Thanks for sharing. I tried this out, but get a error message on statements like \"h\\_height, h\\_width, \\_ = tf.shape(hair)\" since I am not (yet) using eager mode of execution.",
    "915581": "helgith Thank you for letting me know. It will probably require some tweaking to make it work in the training pipeline -- I am planning to get to it next week.\n\nP.S. What version of TensorFlow are you using? I think in TensorFlow 2 eager execution should be enabled by default.",
    "915959": "I'm using TensorFlow 2.2. I have not yet understood the error, but the message is \"OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\"",
    "916067": "The error message seems to come from the map operation in tf.data. You should be able to reproduce it in your notebook with following coding\n\n`import tensorflow as tf\nAUTOTUNE = tf.data.experimental.AUTOTUNE\n\ndef decode\\_image(image\\_path, label=None):\n    #\n    # Read and decode the image\n    bits = tf.io.read\\_file(image\\_path)\n    # dct\\_method='INTEGER\\_ACCURATE' produces the same result as OpenCV\n    img = tf.image.decode\\_jpeg(bits, channels=3, dct\\_method='INTEGER\\_ACCURATE')        \n    # Resize and crop the image\n    img=resize\\_and\\_crop_image(img)  \n    # Creating an augmented image\n    img\\_aug, n\\_hairs = hair\\_aug\\_tf(img)\n    #    \n    return image\n\nand now \n\nds_train = (tf.data.Dataset\n                    .from\\_tensor\\_slices((train\\_images[0:10]))\n                    .map(decode\\_image, num\\_parallel\\_calls=AUTOTUNE)\n                    )`\n\nThis gives an error message \"OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.\". (Possibly the reference to Eager execution is misleading.)",
    "916581": "helgith Thank you for this information -- this is very helpful! I managed to reproduce the error you are referring to. It seems to be related to the peculiarities of the TensorFlow graph mode. I made a few changes in my original code and now it seems to be working in the graph mode. At least I managed to fetch a training batch and print it to the screen. I added this demo code to the very end of my notebook:\n\n[SIIM: Advanced Hair Augmentation in TensorFlow, Version 5](https://www.kaggle.com/graf10a/siim-advanced-hair-augmentation-in-tensorflow/execution)\n\nHope it helps. But please let me know if you discover any other issues. I really appreciate your feedback!",
    "917897": "helgith If you want to see how this augmentation can be included in your training pipeline take a look at Versions 17 (full) or 18 (quick) of the following public notebook of mine:\n\n[EfficientNet BN+Tabular Features TF CV5 512x512](https://www.kaggle.com/graf10a/efficientnet-bn-tabular-features-tf-cv5-512x512).\n\nUPDATE: Use Version 20.",
    "917917": "graf10a I had already included this and was running some test. Thanks for the changes.",
    "918093": "helgith Just wanted to let you know that I discovered an annoying bug in Versions 17 and 18 of my notebook -- because of it the augmentation was not working properly. I found out about it accidentally by printing a training batch to the screen. I tweaked the code of my augmentation function and now the bug is gone. In Version 20 of my notebook you can clearly see the augmentation performed on a training batch. So, if you decide to reference my notebook please use Version 20 -- it is the most bug-free at the moment.",
    "918340": "graf10a I have included the link to Version 20 in my coding."
  },
  "source": "meta"
}