{
  "id": 143326,
  "title": "Padding for image augmentation",
  "url": "/competitions/flower-classification-with-tpus/discussion/143326",
  "author_name": "",
  "post_date": "2020-04-14T17:38:48.118858100Z",
  "votes": 2,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I made a quick modification (<a href=\"https://www.kaggle.com/psaikko/augmentations-with-reflect-padding\">https://www.kaggle.com/psaikko/augmentations-with-reflect-padding</a>) to the data augmentation notebook that everyone seems to be using (<a href=\"https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96\">https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96</a>) to use reflect/mirror padding instead of clipping pixel coordinates which end up outside the original image. </p>\n\n<p>The effect looks nicer to the eye, but is there practical benefit in using it for training a model?</p>\n\n<h1>Reflecting</h1>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2F1fc66a77209ed412a0e808893be3840e%2Fmirror.png?generation=1586885744448584&amp;alt=media\" alt=\"\"></p>\n\n<h1>Clipping</h1>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2Fa5be8c1bcae25c7ce0f8cc643c0a098c%2Fclip.png?generation=1586885765346982&amp;alt=media\" alt=\"\"></p>\n\n<p>This adds a bit of computational overhead. Let me know if you know of a more efficient way to do this, I'm fairly new to tensorflow/kaggle :)</p>",
  "messages": [
    {
      "id": "807521",
      "postDate": "04/14/2020 17:38:48",
      "content": "<p>I made a quick modification (<a href=\"https://www.kaggle.com/psaikko/augmentations-with-reflect-padding\">https://www.kaggle.com/psaikko/augmentations-with-reflect-padding</a>) to the data augmentation notebook that everyone seems to be using (<a href=\"https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96\">https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96</a>) to use reflect/mirror padding instead of clipping pixel coordinates which end up outside the original image. </p>\n\n<p>The effect looks nicer to the eye, but is there practical benefit in using it for training a model?</p>\n\n<h1>Reflecting</h1>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2F1fc66a77209ed412a0e808893be3840e%2Fmirror.png?generation=1586885744448584&amp;alt=media\" alt=\"\"></p>\n\n<h1>Clipping</h1>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2Fa5be8c1bcae25c7ce0f8cc643c0a098c%2Fclip.png?generation=1586885765346982&amp;alt=media\" alt=\"\"></p>\n\n<p>This adds a bit of computational overhead. Let me know if you know of a more efficient way to do this, I'm fairly new to tensorflow/kaggle :)</p>",
      "rawMarkdown": "I made a quick modification (https://www.kaggle.com/psaikko/augmentations-with-reflect-padding) to the data augmentation notebook that everyone seems to be using (https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96) to use reflect/mirror padding instead of clipping pixel coordinates which end up outside the original image. \n\nThe effect looks nicer to the eye, but is there practical benefit in using it for training a model?\n\n# Reflecting\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2F1fc66a77209ed412a0e808893be3840e%2Fmirror.png?generation=1586885744448584&amp;alt=media)\n\n# Clipping\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2Fa5be8c1bcae25c7ce0f8cc643c0a098c%2Fclip.png?generation=1586885765346982&amp;alt=media)\n\nThis adds a bit of computational overhead. Let me know if you know of a more efficient way to do this, I'm fairly new to tensorflow/kaggle :)",
      "votes": null
    },
    {
      "id": "808165",
      "postDate": "04/15/2020 07:26:39",
      "content": "<p>For myself, I like the padding part remain black after the images are rotated. You can pad constant 0 on 4 sides of image then perform the rotation augmentation in Chris`s kernel. After rotated, use \"tf.image.crop_to_bounding_box\" crop the image into original size.</p>",
      "rawMarkdown": "For myself, I like the padding part remain black after the images are rotated. You can pad constant 0 on 4 sides of image then perform the rotation augmentation in Chris`s kernel. After rotated, use \"tf.image.crop_to_bounding_box\" crop the image into original size.",
      "votes": null
    },
    {
      "id": "811061",
      "postDate": "04/17/2020 15:01:40",
      "content": "<p>Thanks for the tip! I implemented that in the notebook as well now. Do you prefer that for efficiency or to avoid introducing unwanted artifacts?  </p>",
      "rawMarkdown": "Thanks for the tip! I implemented that in the notebook as well now. Do you prefer that for efficiency or to avoid introducing unwanted artifacts?",
      "votes": null
    },
    {
      "id": "811490",
      "postDate": "04/18/2020 01:14:59",
      "content": "<p>I think the main purpose is to avoid the artifacts, I concerned the stretch out border might confuse the model by treating them as some unique features. But I think reflecting is fine.</p>",
      "rawMarkdown": "I think the main purpose is to avoid the artifacts, I concerned the stretch out border might confuse the model by treating them as some unique features. But I think reflecting is fine.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 808165,
      "author_name": "xiejialun",
      "author_url": "",
      "post_date": "04/15/2020 07:26:39",
      "content": "<p>For myself, I like the padding part remain black after the images are rotated. You can pad constant 0 on 4 sides of image then perform the rotation augmentation in Chris`s kernel. After rotated, use \"tf.image.crop_to_bounding_box\" crop the image into original size.</p>",
      "votes": null,
      "replies": [
        {
          "id": 811061,
          "author_name": "psaikko",
          "author_url": "",
          "post_date": "04/17/2020 15:01:40",
          "content": "<p>Thanks for the tip! I implemented that in the notebook as well now. Do you prefer that for efficiency or to avoid introducing unwanted artifacts?  </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 811490,
          "author_name": "xiejialun",
          "author_url": "",
          "post_date": "04/18/2020 01:14:59",
          "content": "<p>I think the main purpose is to avoid the artifacts, I concerned the stretch out border might confuse the model by treating them as some unique features. But I think reflecting is fine.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "807521": "I made a quick modification (https://www.kaggle.com/psaikko/augmentations-with-reflect-padding) to the data augmentation notebook that everyone seems to be using (https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96) to use reflect/mirror padding instead of clipping pixel coordinates which end up outside the original image. \n\nThe effect looks nicer to the eye, but is there practical benefit in using it for training a model?\n\n# Reflecting\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2F1fc66a77209ed412a0e808893be3840e%2Fmirror.png?generation=1586885744448584&amp;alt=media)\n\n# Clipping\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2372475%2Fa5be8c1bcae25c7ce0f8cc643c0a098c%2Fclip.png?generation=1586885765346982&amp;alt=media)\n\nThis adds a bit of computational overhead. Let me know if you know of a more efficient way to do this, I'm fairly new to tensorflow/kaggle :)",
    "808165": "For myself, I like the padding part remain black after the images are rotated. You can pad constant 0 on 4 sides of image then perform the rotation augmentation in Chris`s kernel. After rotated, use \"tf.image.crop_to_bounding_box\" crop the image into original size.",
    "811061": "Thanks for the tip! I implemented that in the notebook as well now. Do you prefer that for efficiency or to avoid introducing unwanted artifacts?",
    "811490": "I think the main purpose is to avoid the artifacts, I concerned the stretch out border might confuse the model by treating them as some unique features. But I think reflecting is fine."
  },
  "source": "meta"
}