{
  "id": 187306,
  "title": "Did anyone come up with Augmentations ? ",
  "url": "/competitions/rsna-str-pulmonary-embolism-detection/discussion/187306",
  "author_name": "Athar Sayed",
  "post_date": "2020-09-28T11:59:56.798000",
  "votes": 5,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Despite the dataset being extremely large here one thing I noticed in Computer Vision Competitions is use of Augmentations , I have not seen any discussion or Public Kernel Talk about this , I also want to ask people having expertise in Medical Domain whether Augmentations are suited for this Task of Pulmonary Embolism Detection using series of CT Scan images ?</p>",
  "messages": [
    {
      "id": 1030129,
      "postDate": "2020-09-28T12:41:39.720Z",
      "content": "<p><a href=\"https://www.kaggle.com/sayedathar11\" target=\"_blank\">@sayedathar11</a> The dataset is very large, but a lot of images are very similar =&gt; over fitting is very easy.<br>\nAugmentation: the usual augmentation are ok: Rotation, Flip, ResizeCrop, CutOut</p>",
      "rawMarkdown": "@sayedathar11 The dataset is very large, but a lot of images are very similar => over fitting is very easy.\nAugmentation: the usual augmentation are ok: Rotation, Flip, ResizeCrop, CutOut",
      "votes": 5,
      "replies": [
        {
          "id": 1032679,
          "postDate": "2020-09-30T11:09:28.357Z",
          "content": "<p>I think we should be careful with rotation- and flip-based augmentations since some labels (e.g. RV/LV ratio or leftsided/rightsided PE) refer to specific locations on the image.</p>",
          "rawMarkdown": "I think we should be careful with rotation- and flip-based augmentations since some labels (e.g. RV/LV ratio or leftsided/rightsided PE) refer to specific locations on the image.",
          "votes": 2
        },
        {
          "id": 1032715,
          "postDate": "2020-09-30T11:52:22.610Z",
          "content": "<p>This is exactly why you need this augmentation!<br>\nThe way to decide where is left and where is right is to <strong>find where the hart is</strong>.<br>\nThe original image may be flipped for some reason</p>",
          "rawMarkdown": "This is exactly why you need this augmentation!\nThe way to decide where is left and where is right is to **find where the hart is**.\nThe original image may be flipped for some reason",
          "votes": 7
        },
        {
          "id": 1032738,
          "postDate": "2020-09-30T12:19:33.940Z",
          "content": "<p>Good point, makes sense! An alternative approach could be to use the DCM meta-data to figure out the 'right' way to rotate the image during preprocessing to ensure consistency.</p>",
          "rawMarkdown": "Good point, makes sense! An alternative approach could be to use the DCM meta-data to figure out the 'right' way to rotate the image during preprocessing to ensure consistency.",
          "votes": 2
        },
        {
          "id": 1059318,
          "postDate": "2020-10-24T23:13:34.603Z",
          "content": "<blockquote>\n  <p>This is exactly why you need this augmentation!</p>\n</blockquote>\n<p>Thanks for this insight.</p>",
          "rawMarkdown": "> This is exactly why you need this augmentation!\n\nThanks for this insight.",
          "votes": 1
        }
      ]
    },
    {
      "id": 1030081,
      "postDate": "2020-09-28T11:59:56.797Z",
      "content": "<p>Despite the dataset being extremely large here one thing I noticed in Computer Vision Competitions is use of Augmentations , I have not seen any discussion or Public Kernel Talk about this , I also want to ask people having expertise in Medical Domain whether Augmentations are suited for this Task of Pulmonary Embolism Detection using series of CT Scan images ?</p>",
      "rawMarkdown": "Despite the dataset being extremely large here one thing I noticed in Computer Vision Competitions is use of Augmentations , I have not seen any discussion or Public Kernel Talk about this , I also want to ask people having expertise in Medical Domain whether Augmentations are suited for this Task of Pulmonary Embolism Detection using series of CT Scan images ?",
      "votes": 5
    },
    {
      "id": 1030493,
      "postDate": "2020-09-28T17:31:56.913Z",
      "content": "<h2>Flipping <a></a></h2>\n<p>Flipping is a simple transformation that involves index-switching on the image channels. In vertical flipping, the order of rows is exchanged, whereas in vertical flipping, the order of rows is exchanged. Let us assume that <em>Aijk</em> (of size <em>(m, n, 3)</em>) is the image we want to flip. Horizontal and vertical flipping can be represented by the transformations below:</p>\n<p><img src=\"https://i.imgur.com/B9y5apl.png\"><br>\n<img src=\"https://i.imgur.com/eQ1dyvN.png\"><br>\n<img src=\"https://i.imgur.com/i30LQgq.png\"><br>\n<br></p>\n<p>After Flipping, we can see that the images are simply flipped. All major features in the image remain the same, but to a computer algorithm, the flipped images look completely different. These transformations can be used for data augmentation, making models more robust and accurate.</p>\n<p>Implementation:</p>\n<pre><code>def data_augment(image, label=None):\n    image = tf.image.random_flip_left_right(image)\n    image = tf.image.random_flip_up_down(image)\n\n    if label is None:\n        return image\n    else:\n        return image, label\n\nAUTO = tf.data.experimental.AUTOTUNE\n\ntrain_dataset = (\n    tf.data.Dataset\n    .from_tensor_slices((train_paths, train_labels))]\n    .map(data_augment, num_parallel_calls=AUTO)\n    .repeat()\n    .shuffle(512)\n    .batch(BATCH_SIZE)\n    .prefetch(AUTO)\n)\n</code></pre>\n<blockquote>\n  <ol>\n  <li><p>Shuffle : the file names will be shuffled randomly</p></li>\n  <li><p>Repeat: Repeats the dataset so each original value is seen multiple times , since we are <br>\n         randomly augmenting(flipping) our images</p></li>\n  <li><p>Prefetch : This allows later elements to be prepared while the current element is being processed. <br>\n            This often improves latency and throughput, at the cost of using additional memory to store <br>\n            prefetched elements.</p></li>\n  <li><p>num_parallel_calls : tf.data.experimental.AUTOTUNE is used, then the number of parallel calls <br>\n                      is set dynamically based on available CPU.</p></li>\n  </ol>\n</blockquote>\n<p>For Complete understanding, visit : <a href=\"https://www.kaggle.com/ashrafkhan94/plant-diseases-img-pro-tpu-densenet-efficentnet\" target=\"_blank\">https://www.kaggle.com/ashrafkhan94/plant-diseases-img-pro-tpu-densenet-efficentnet</a></p>",
      "rawMarkdown": "## Flipping <a id=\"2.2\"></a>\n\nFlipping is a simple transformation that involves index-switching on the image channels. In vertical flipping, the order of rows is exchanged, whereas in vertical flipping, the order of rows is exchanged. Let us assume that *A<sub>ijk</sub>* (of size *(m, n, 3)*) is the image we want to flip. Horizontal and vertical flipping can be represented by the transformations below:\n\n<center><img src=\"https://i.imgur.com/B9y5apl.png\" width=\"135px\"></center>\n<center><img src=\"https://i.imgur.com/eQ1dyvN.png\" width=\"305px\"></center>\n<center><img src=\"https://i.imgur.com/i30LQgq.png\" width=\"305px\"></center>\n<br>\n\nAfter Flipping, we can see that the images are simply flipped. All major features in the image remain the same, but to a computer algorithm, the flipped images look completely different. These transformations can be used for data augmentation, making models more robust and accurate.\n\nImplementation:\n\n```\ndef data_augment(image, label=None):\n    image = tf.image.random_flip_left_right(image)\n    image = tf.image.random_flip_up_down(image)\n    \n    if label is None:\n        return image\n    else:\n        return image, label\n\nAUTO = tf.data.experimental.AUTOTUNE\n\ntrain_dataset = (\n    tf.data.Dataset\n    .from_tensor_slices((train_paths, train_labels))]\n    .map(data_augment, num_parallel_calls=AUTO)\n    .repeat()\n    .shuffle(512)\n    .batch(BATCH_SIZE)\n    .prefetch(AUTO)\n)\n```\n\n> 1. Shuffle : the file names will be shuffled randomly\n\n> 2. Repeat: Repeats the dataset so each original value is seen multiple times , since we are \n           randomly augmenting(flipping) our images\n\n> 3. Prefetch : This allows later elements to be prepared while the current element is being processed. \n              This often improves latency and throughput, at the cost of using additional memory to store \n              prefetched elements.\n\n> 4. num_parallel_calls : tf.data.experimental.AUTOTUNE is used, then the number of parallel calls \n                        is set dynamically based on available CPU.\n\nFor Complete understanding, visit : https://www.kaggle.com/ashrafkhan94/plant-diseases-img-pro-tpu-densenet-efficentnet"
    },
    {
      "id": 1031136,
      "postDate": "2020-09-29T09:06:28.883Z",
      "content": "<p>good job ! good</p>",
      "rawMarkdown": "good job ! good",
      "votes": -5
    },
    {
      "id": 1030140,
      "postDate": "2020-09-28T12:49:03.520Z",
      "content": "<p>ok <a href=\"https://www.kaggle.com/yuval6967\" target=\"_blank\">@yuval6967</a> will first try to build models without augmentations and then will apply augmentation if it improves results.</p>",
      "rawMarkdown": "ok @yuval6967 will first try to build models without augmentations and then will apply augmentation if it improves results."
    }
  ],
  "comments": [
    {
      "id": 1030129,
      "author_name": "yuval reina",
      "author_url": "",
      "post_date": "2020-09-28T12:41:39.720000",
      "content": "<p><a href=\"https://www.kaggle.com/sayedathar11\" target=\"_blank\">@sayedathar11</a> The dataset is very large, but a lot of images are very similar =&gt; over fitting is very easy.<br>\nAugmentation: the usual augmentation are ok: Rotation, Flip, ResizeCrop, CutOut</p>",
      "votes": 5,
      "replies": [
        {
          "id": 1032679,
          "author_name": "Nikita Kozodoi",
          "author_url": "",
          "post_date": "2020-09-30T11:09:28.357000",
          "content": "<p>I think we should be careful with rotation- and flip-based augmentations since some labels (e.g. RV/LV ratio or leftsided/rightsided PE) refer to specific locations on the image.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1032715,
          "author_name": "yuval reina",
          "author_url": "",
          "post_date": "2020-09-30T11:52:22.610000",
          "content": "<p>This is exactly why you need this augmentation!<br>\nThe way to decide where is left and where is right is to <strong>find where the hart is</strong>.<br>\nThe original image may be flipped for some reason</p>",
          "votes": 7,
          "replies": []
        },
        {
          "id": 1032738,
          "author_name": "Nikita Kozodoi",
          "author_url": "",
          "post_date": "2020-09-30T12:19:33.940000",
          "content": "<p>Good point, makes sense! An alternative approach could be to use the DCM meta-data to figure out the 'right' way to rotate the image during preprocessing to ensure consistency.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1059318,
          "author_name": "عثمان",
          "author_url": "",
          "post_date": "2020-10-24T23:13:34.603000",
          "content": "<blockquote>\n  <p>This is exactly why you need this augmentation!</p>\n</blockquote>\n<p>Thanks for this insight.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1030493,
      "author_name": "Ashraf Khan",
      "author_url": "",
      "post_date": "2020-09-28T17:31:56.913000",
      "content": "<h2>Flipping <a></a></h2>\n<p>Flipping is a simple transformation that involves index-switching on the image channels. In vertical flipping, the order of rows is exchanged, whereas in vertical flipping, the order of rows is exchanged. Let us assume that <em>Aijk</em> (of size <em>(m, n, 3)</em>) is the image we want to flip. Horizontal and vertical flipping can be represented by the transformations below:</p>\n<p><img src=\"https://i.imgur.com/B9y5apl.png\"><br>\n<img src=\"https://i.imgur.com/eQ1dyvN.png\"><br>\n<img src=\"https://i.imgur.com/i30LQgq.png\"><br>\n<br></p>\n<p>After Flipping, we can see that the images are simply flipped. All major features in the image remain the same, but to a computer algorithm, the flipped images look completely different. These transformations can be used for data augmentation, making models more robust and accurate.</p>\n<p>Implementation:</p>\n<pre><code>def data_augment(image, label=None):\n    image = tf.image.random_flip_left_right(image)\n    image = tf.image.random_flip_up_down(image)\n\n    if label is None:\n        return image\n    else:\n        return image, label\n\nAUTO = tf.data.experimental.AUTOTUNE\n\ntrain_dataset = (\n    tf.data.Dataset\n    .from_tensor_slices((train_paths, train_labels))]\n    .map(data_augment, num_parallel_calls=AUTO)\n    .repeat()\n    .shuffle(512)\n    .batch(BATCH_SIZE)\n    .prefetch(AUTO)\n)\n</code></pre>\n<blockquote>\n  <ol>\n  <li><p>Shuffle : the file names will be shuffled randomly</p></li>\n  <li><p>Repeat: Repeats the dataset so each original value is seen multiple times , since we are <br>\n         randomly augmenting(flipping) our images</p></li>\n  <li><p>Prefetch : This allows later elements to be prepared while the current element is being processed. <br>\n            This often improves latency and throughput, at the cost of using additional memory to store <br>\n            prefetched elements.</p></li>\n  <li><p>num_parallel_calls : tf.data.experimental.AUTOTUNE is used, then the number of parallel calls <br>\n                      is set dynamically based on available CPU.</p></li>\n  </ol>\n</blockquote>\n<p>For Complete understanding, visit : <a href=\"https://www.kaggle.com/ashrafkhan94/plant-diseases-img-pro-tpu-densenet-efficentnet\" target=\"_blank\">https://www.kaggle.com/ashrafkhan94/plant-diseases-img-pro-tpu-densenet-efficentnet</a></p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1031136,
      "author_name": "Naim Mhedhbi",
      "author_url": "",
      "post_date": "2020-09-29T09:06:28.883000",
      "content": "<p>good job ! good</p>",
      "votes": -5,
      "replies": []
    },
    {
      "id": 1030140,
      "author_name": "Athar Sayed",
      "author_url": "",
      "post_date": "2020-09-28T12:49:03.520000",
      "content": "<p>ok <a href=\"https://www.kaggle.com/yuval6967\" target=\"_blank\">@yuval6967</a> will first try to build models without augmentations and then will apply augmentation if it improves results.</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1030129": "@sayedathar11 The dataset is very large, but a lot of images are very similar => over fitting is very easy.\nAugmentation: the usual augmentation are ok: Rotation, Flip, ResizeCrop, CutOut",
    "1030081": "Despite the dataset being extremely large here one thing I noticed in Computer Vision Competitions is use of Augmentations , I have not seen any discussion or Public Kernel Talk about this , I also want to ask people having expertise in Medical Domain whether Augmentations are suited for this Task of Pulmonary Embolism Detection using series of CT Scan images ?",
    "1030493": "## Flipping <a id=\"2.2\"></a>\n\nFlipping is a simple transformation that involves index-switching on the image channels. In vertical flipping, the order of rows is exchanged, whereas in vertical flipping, the order of rows is exchanged. Let us assume that *A<sub>ijk</sub>* (of size *(m, n, 3)*) is the image we want to flip. Horizontal and vertical flipping can be represented by the transformations below:\n\n<center><img src=\"https://i.imgur.com/B9y5apl.png\" width=\"135px\"></center>\n<center><img src=\"https://i.imgur.com/eQ1dyvN.png\" width=\"305px\"></center>\n<center><img src=\"https://i.imgur.com/i30LQgq.png\" width=\"305px\"></center>\n<br>\n\nAfter Flipping, we can see that the images are simply flipped. All major features in the image remain the same, but to a computer algorithm, the flipped images look completely different. These transformations can be used for data augmentation, making models more robust and accurate.\n\nImplementation:\n\n```\ndef data_augment(image, label=None):\n    image = tf.image.random_flip_left_right(image)\n    image = tf.image.random_flip_up_down(image)\n    \n    if label is None:\n        return image\n    else:\n        return image, label\n\nAUTO = tf.data.experimental.AUTOTUNE\n\ntrain_dataset = (\n    tf.data.Dataset\n    .from_tensor_slices((train_paths, train_labels))]\n    .map(data_augment, num_parallel_calls=AUTO)\n    .repeat()\n    .shuffle(512)\n    .batch(BATCH_SIZE)\n    .prefetch(AUTO)\n)\n```\n\n> 1. Shuffle : the file names will be shuffled randomly\n\n> 2. Repeat: Repeats the dataset so each original value is seen multiple times , since we are \n           randomly augmenting(flipping) our images\n\n> 3. Prefetch : This allows later elements to be prepared while the current element is being processed. \n              This often improves latency and throughput, at the cost of using additional memory to store \n              prefetched elements.\n\n> 4. num_parallel_calls : tf.data.experimental.AUTOTUNE is used, then the number of parallel calls \n                        is set dynamically based on available CPU.\n\nFor Complete understanding, visit : https://www.kaggle.com/ashrafkhan94/plant-diseases-img-pro-tpu-densenet-efficentnet",
    "1031136": "good job ! good",
    "1030140": "ok @yuval6967 will first try to build models without augmentations and then will apply augmentation if it improves results."
  }
}