{
  "id": 212005,
  "title": "Noise from ImageDataGenerator",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/212005",
  "author_name": "",
  "post_date": "2021-01-17T05:58:44.468093100Z",
  "votes": -1,
  "comment_count": 3,
  "views": 0,
  "content": "<p><a href=\"url\" target=\"_blank\"><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5130427%2F14f86eba939034399bf94120d6ad8d6e%2Fda.png?generation=1610863009463302&amp;alt=media\" alt=\"\"></a></p>\n<p>In the above image it can be seen that the left and the upper side has lines which has been created by ImageDataGenerator.<br>\nQuestion- Is there a way this can be reduced? Because ultimately every image has this and it must be a lot of noise for the model and must be effecting the model accuracy significantly!</p>",
  "messages": [
    {
      "id": "1156385",
      "postDate": "01/17/2021 05:58:44",
      "content": "<p><a href=\"url\" target=\"_blank\"><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5130427%2F14f86eba939034399bf94120d6ad8d6e%2Fda.png?generation=1610863009463302&amp;alt=media\" alt=\"\"></a></p>\n<p>In the above image it can be seen that the left and the upper side has lines which has been created by ImageDataGenerator.<br>\nQuestion- Is there a way this can be reduced? Because ultimately every image has this and it must be a lot of noise for the model and must be effecting the model accuracy significantly!</p>",
      "rawMarkdown": "[![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5130427%2F14f86eba939034399bf94120d6ad8d6e%2Fda.png?generation=1610863009463302&alt=media)](url)\n\nIn the above image it can be seen that the left and the upper side has lines which has been created by ImageDataGenerator.\nQuestion- Is there a way this can be reduced? Because ultimately every image has this and it must be a lot of noise for the model and must be effecting the model accuracy significantly!",
      "votes": null
    },
    {
      "id": "1156509",
      "postDate": "01/17/2021 07:59:10",
      "content": "<p>According to <strong><a href=\"https://keras.io/api/preprocessing/image/#flowfromdirectory-method\" target=\"_blank\">Keras Documentation</a></strong>, the <code>interpolation</code> argument (which defines how to fulfill the blank parts of the augmented image) is set to <code>nearest</code> by default, that's where these lines come from. You can try to change it to <code>bilinear</code> or <code>bicubic</code>. <br>\nHowever, I would suggest leaving it to default, as it is rather common practice. If your model suffers from introducing augmentation, try to reduce <code>rotation_range</code>, <code>width_shift_range</code>, <code>height_shift_range</code>, and other arguments you pass to <code>ImageDataGenerator</code> instance.</p>",
      "rawMarkdown": "According to **[Keras Documentation](https://keras.io/api/preprocessing/image/#flowfromdirectory-method)**, the `interpolation` argument (which defines how to fulfill the blank parts of the augmented image) is set to `nearest` by default, that's where these lines come from. You can try to change it to `bilinear` or `bicubic`. \nHowever, I would suggest leaving it to default, as it is rather common practice. If your model suffers from introducing augmentation, try to reduce `rotation_range`, `width_shift_range`, `height_shift_range`, and other arguments you pass to `ImageDataGenerator` instance.",
      "votes": null
    },
    {
      "id": "1156567",
      "postDate": "01/17/2021 08:58:45",
      "content": "<p>Change the fill mode:<br>\nfill_mode = 'reflect'</p>\n<p>This replaces the \"noise\" with the reflected image adjacent to that edge.  </p>",
      "rawMarkdown": "Change the fill mode:\nfill_mode = 'reflect'\n\nThis replaces the \"noise\" with the reflected image adjacent to that edge.",
      "votes": null
    },
    {
      "id": "1156572",
      "postDate": "01/17/2021 09:04:02",
      "content": "<p>Add an augmentation layer to the model - do the crop to the desired size there.  In the generator bring the image in at larger size than you will use for the model.  </p>\n<p>The noise is the result of the padding created when you do transformations that result in more pixels needed to fill in gaps.  For example if you rotate a 800x600 image and than crop to 512x512 most of the \"noise\" is cropped out.  </p>",
      "rawMarkdown": "Add an augmentation layer to the model - do the crop to the desired size there.  In the generator bring the image in at larger size than you will use for the model.  \n\nThe noise is the result of the padding created when you do transformations that result in more pixels needed to fill in gaps.  For example if you rotate a 800x600 image and than crop to 512x512 most of the \"noise\" is cropped out.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1156509,
      "author_name": "nickuzmenkov",
      "author_url": "",
      "post_date": "01/17/2021 07:59:10",
      "content": "<p>According to <strong><a href=\"https://keras.io/api/preprocessing/image/#flowfromdirectory-method\" target=\"_blank\">Keras Documentation</a></strong>, the <code>interpolation</code> argument (which defines how to fulfill the blank parts of the augmented image) is set to <code>nearest</code> by default, that's where these lines come from. You can try to change it to <code>bilinear</code> or <code>bicubic</code>. <br>\nHowever, I would suggest leaving it to default, as it is rather common practice. If your model suffers from introducing augmentation, try to reduce <code>rotation_range</code>, <code>width_shift_range</code>, <code>height_shift_range</code>, and other arguments you pass to <code>ImageDataGenerator</code> instance.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1156567,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "01/17/2021 08:58:45",
      "content": "<p>Change the fill mode:<br>\nfill_mode = 'reflect'</p>\n<p>This replaces the \"noise\" with the reflected image adjacent to that edge.  </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1156572,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "01/17/2021 09:04:02",
      "content": "<p>Add an augmentation layer to the model - do the crop to the desired size there.  In the generator bring the image in at larger size than you will use for the model.  </p>\n<p>The noise is the result of the padding created when you do transformations that result in more pixels needed to fill in gaps.  For example if you rotate a 800x600 image and than crop to 512x512 most of the \"noise\" is cropped out.  </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1156385": "[![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5130427%2F14f86eba939034399bf94120d6ad8d6e%2Fda.png?generation=1610863009463302&alt=media)](url)\n\nIn the above image it can be seen that the left and the upper side has lines which has been created by ImageDataGenerator.\nQuestion- Is there a way this can be reduced? Because ultimately every image has this and it must be a lot of noise for the model and must be effecting the model accuracy significantly!",
    "1156509": "According to **[Keras Documentation](https://keras.io/api/preprocessing/image/#flowfromdirectory-method)**, the `interpolation` argument (which defines how to fulfill the blank parts of the augmented image) is set to `nearest` by default, that's where these lines come from. You can try to change it to `bilinear` or `bicubic`. \nHowever, I would suggest leaving it to default, as it is rather common practice. If your model suffers from introducing augmentation, try to reduce `rotation_range`, `width_shift_range`, `height_shift_range`, and other arguments you pass to `ImageDataGenerator` instance.",
    "1156567": "Change the fill mode:\nfill_mode = 'reflect'\n\nThis replaces the \"noise\" with the reflected image adjacent to that edge.",
    "1156572": "Add an augmentation layer to the model - do the crop to the desired size there.  In the generator bring the image in at larger size than you will use for the model.  \n\nThe noise is the result of the padding created when you do transformations that result in more pixels needed to fill in gaps.  For example if you rotate a 800x600 image and than crop to 512x512 most of the \"noise\" is cropped out."
  },
  "source": "meta"
}