{
  "id": 49683,
  "title": "Data Augmentation Hurts",
  "url": "/competitions/data-science-bowl-2018/discussion/49683",
  "author_name": "",
  "post_date": "2018-02-14T07:08:09.870666100Z",
  "votes": 5,
  "comment_count": 16,
  "views": 0,
  "content": "<p>I have been trying to make data augmentation work for a long time, but it has repeatedly hurt my LB score. The way I do augmentation is following: For each (image, list of masks) pair,  I generate 8 (image, list of masks) pairs by rotating the image and masks by 90, 180 and 270 degrees, flipping horizontally, flipping vertically and combining these operations to generate 8 different possibilities (A square has eight symmetries).</p>\n\n<p>However, my LB score always drops when I use augmentation. FWIW I am using Mask RCNN. Has anyone else faced a similar problem?</p>\n\n<p>I initially suspected that I may be doing augmentation incorrectly, but I have checked augmented image and masks: they seem to be alright.</p>",
  "messages": [
    {
      "id": "282566",
      "postDate": "02/14/2018 07:08:09",
      "content": "<p>I have been trying to make data augmentation work for a long time, but it has repeatedly hurt my LB score. The way I do augmentation is following: For each (image, list of masks) pair,  I generate 8 (image, list of masks) pairs by rotating the image and masks by 90, 180 and 270 degrees, flipping horizontally, flipping vertically and combining these operations to generate 8 different possibilities (A square has eight symmetries).</p>\n\n<p>However, my LB score always drops when I use augmentation. FWIW I am using Mask RCNN. Has anyone else faced a similar problem?</p>\n\n<p>I initially suspected that I may be doing augmentation incorrectly, but I have checked augmented image and masks: they seem to be alright.</p>",
      "rawMarkdown": "I have been trying to make data augmentation work for a long time, but it has repeatedly hurt my LB score. The way I do augmentation is following: For each (image, list of masks) pair,  I generate 8 (image, list of masks) pairs by rotating the image and masks by 90, 180 and 270 degrees, flipping horizontally, flipping vertically and combining these operations to generate 8 different possibilities (A square has eight symmetries).\n\nHowever, my LB score always drops when I use augmentation. FWIW I am using Mask RCNN. Has anyone else faced a similar problem?\n\nI initially suspected that I may be doing augmentation incorrectly, but I have checked augmented image and masks: they seem to be alright.",
      "votes": null
    },
    {
      "id": "282569",
      "postDate": "02/14/2018 07:16:54",
      "content": "<p>Did you make sure masks match the image after augmentation? And did you check not doing augmentation for test set?</p>",
      "rawMarkdown": "Did you make sure masks match the image after augmentation? And did you check not doing augmentation for test set?",
      "votes": null
    },
    {
      "id": "282634",
      "postDate": "02/14/2018 09:45:12",
      "content": "<p>Yes, I had checked (image, mask) pairs after augmentation, and they appeared to be correct. I will check again, more throughly. </p>\n\n<p>I am not doing augmentation at test time.</p>\n\n<p>At this point I have two hypotheses:\n- Maybe I am doing augmentation incorrectly. I have visually seen (image, mask) pairs after augmentation and they seem alright, but I'll do more through checking.\n- May be, I just need to train more, since there is more data. I am currently in the process of training much more and will report if I see any boost in the score.</p>",
      "rawMarkdown": "Yes, I had checked (image, mask) pairs after augmentation, and they appeared to be correct. I will check again, more throughly. \n\nI am not doing augmentation at test time.\n\nAt this point I have two hypotheses:\n- Maybe I am doing augmentation incorrectly. I have visually seen (image, mask) pairs after augmentation and they seem alright, but I'll do more through checking.\n- May be, I just need to train more, since there is more data. I am currently in the process of training much more and will report if I see any boost in the score.",
      "votes": null
    },
    {
      "id": "282706",
      "postDate": "02/14/2018 12:38:39",
      "content": "<p>Are you using <a href=\"http://github.com/matterport/Mask_RCNN\">Mask RCNN</a> library to build the model? There is a random horizontal flip as augmentation I use the code with that and I was able to achieve 0.409 in the LB.</p>",
      "rawMarkdown": "Are you using [Mask RCNN][1] library to build the model? There is a random horizontal flip as augmentation I use the code with that and I was able to achieve 0.409 in the LB.\n\n  [1]: http://github.com/matterport/Mask_RCNN",
      "votes": null
    },
    {
      "id": "282822",
      "postDate": "02/14/2018 16:46:39",
      "content": "<p>Yes, I am using the library you referred. I know about random horizontal flip, but I wanted to add more augmentations. I have also got 0.412 with that method, but can't go beyond that even with more augmentations.</p>",
      "rawMarkdown": "Yes, I am using the library you referred. I know about random horizontal flip, but I wanted to add more augmentations. I have also got 0.412 with that method, but can't go beyond that even with more augmentations.",
      "votes": null
    },
    {
      "id": "282946",
      "postDate": "02/14/2018 19:55:30",
      "content": "<p>Check if the augmented images have the same scale than the original. When I was testing some augmentation, the original images are in [0-255] range, after a resize they became floats [0-1]</p>",
      "rawMarkdown": "Check if the augmented images have the same scale than the original. When I was testing some augmentation, the original images are in [0-255] range, after a resize they became floats [0-1]",
      "votes": null
    },
    {
      "id": "282951",
      "postDate": "02/14/2018 20:00:09",
      "content": "<p>Yes, specially if one uses <code>skimage.transform.resize</code>. To avoid that, I use <code>preserve_range=True</code> option and convert the returned image to <code>uint</code>.</p>",
      "rawMarkdown": "Yes, specially if one uses `skimage.transform.resize`. To avoid that, I use `preserve_range=True` option and convert the returned image to `uint`.",
      "votes": null
    },
    {
      "id": "282988",
      "postDate": "02/14/2018 20:45:05",
      "content": "<p>Yep. This is a crucial tip (and could likely be responsible for issue)!</p>\n\n<p>I’m curious, are you augmenting both your training and validation set?</p>\n\n<p><em>But it’s also worth noting that additional augmentation will require additional training (and possibly additional parameter capacity). I’d also avoid comparing augmented scores to non-augmented scores since one model is likely overfit and the other is likely underfit).</em></p>",
      "rawMarkdown": "Yep. This is a crucial tip (and could likely be responsible for issue)!\n\nI’m curious, are you augmenting both your training and validation set?\n\n*But it’s also worth noting that additional augmentation will require additional training (and possibly additional parameter capacity). I’d also avoid comparing augmented scores to non-augmented scores since one model is likely overfit and the other is likely underfit).*",
      "votes": null
    },
    {
      "id": "283168",
      "postDate": "02/15/2018 01:34:21",
      "content": "<p>I made a submission with 90 degrees rotation horizontal and vertical flips (I used numpy functions flipud rot90 and fliplr) But it still got 0.409 and I think the issue is with detecting the color images (histology). I think we should try some of the color augmentations that Allen mentioned in his post <a href=\"https://www.kaggle.com/c/data-science-bowl-2018/discussion/48130#282959\">https://www.kaggle.com/c/data-science-bowl-2018/discussion/48130#282959</a></p>",
      "rawMarkdown": "I made a submission with 90 degrees rotation horizontal and vertical flips (I used numpy functions flipud rot90 and fliplr) But it still got 0.409 and I think the issue is with detecting the color images (histology). I think we should try some of the color augmentations that Allen mentioned in his post https://www.kaggle.com/c/data-science-bowl-2018/discussion/48130#282959",
      "votes": null
    },
    {
      "id": "283218",
      "postDate": "02/15/2018 04:30:35",
      "content": "<p>That's such nice tip. However, I use np.tranpose() and np.flip() to do my augmentations, so there is no chance of this phenomena.</p>",
      "rawMarkdown": "That's such nice tip. However, I use np.tranpose() and np.flip() to do my augmentations, so there is no chance of this phenomena.",
      "votes": null
    },
    {
      "id": "283271",
      "postDate": "02/15/2018 06:16:37",
      "content": "<p>@Allen Goodman, comparing <code>train loss</code> and <code>validation loss</code> will help us to identify if the model is overfitted or not, am I right? If this is the case, we can still compare the two models.</p>",
      "rawMarkdown": "Allen Goodman, comparing `train loss` and `validation loss` will help us to identify if the model is overfitted or not, am I right? If this is the case, we can still compare the two models.",
      "votes": null
    },
    {
      "id": "283390",
      "postDate": "02/15/2018 12:22:36",
      "content": "<p>Can it be a result of incorrect splitting between training and validation images? </p>",
      "rawMarkdown": "Can it be a result of incorrect splitting between training and validation images?",
      "votes": null
    },
    {
      "id": "283395",
      "postDate": "02/15/2018 13:08:03",
      "content": "<p>I use one image set for training, and other for validation.</p>",
      "rawMarkdown": "I use one image set for training, and other for validation.",
      "votes": null
    },
    {
      "id": "283398",
      "postDate": "02/15/2018 13:11:27",
      "content": "<p>By now, I have given up on making simple flip/rotation augmentations.  Maybe, it is incorrect to expect an improvement by using these augmentations: convolution filters scan over whole images and they will learn same features whether they are located in this part of the image or that part of the image. </p>\n\n<p>Perhaps augmentations like zoom/crop/brightness/noise will help, but not simple rotation and flip.</p>\n\n<p>If someone finds their scores improved by rotation/flip, kindly let me know.</p>\n\n<p>Thanks,\nVivek</p>",
      "rawMarkdown": "By now, I have given up on making simple flip/rotation augmentations.  Maybe, it is incorrect to expect an improvement by using these augmentations: convolution filters scan over whole images and they will learn same features whether they are located in this part of the image or that part of the image. \n\nPerhaps augmentations like zoom/crop/brightness/noise will help, but not simple rotation and flip.\n\nIf someone finds their scores improved by rotation/flip, kindly let me know.\n\nThanks,\nVivek",
      "votes": null
    },
    {
      "id": "283871",
      "postDate": "02/16/2018 05:22:31",
      "content": "<p>i haven't try LB submission yet. My experiments showed better results for validation loss as follows:</p>\n\n<p>.</p>\n\n<p>augmentation-0:  no augmentation</p>\n\n<p>augmentation-1: horizontal-flip, vertical-flip, various 90-degree rotation</p>\n\n<p>augmentation-2: augmentation-1 and scale/shift/rotate</p>\n\n<p>augmentation-3: augmentation-1 and contrast/brightness shift</p>\n\n<p>.</p>\n\n<p>in mask-rcnn, there are 4 loss:</p>\n\n<ul>\n<li><p>rpn_cls_loss/rpn_reg_loss : no so much affected by augmentation-1/2/3</p></li>\n<li><p>rcnn_cls_loss : augmentation-1/2 is better than augmentation-0. augmentation-2 is the best. augmentation-3 get worst</p></li>\n<li><p>rcnn_reg_loss : no so much affected by augmentation-1/2/3</p></li>\n<li><p>mask_loss : no so much affected by augmentation-1/2/3</p></li>\n</ul>",
      "rawMarkdown": "i haven't try LB submission yet. My experiments showed better results for validation loss as follows:\n\n.\n\naugmentation-0:  no augmentation\n\naugmentation-1: horizontal-flip, vertical-flip, various 90-degree rotation\n\naugmentation-2: augmentation-1 and scale/shift/rotate\n\naugmentation-3: augmentation-1 and contrast/brightness shift\n\n.\n\n\nin mask-rcnn, there are 4 loss:\n\n  - rpn_cls_loss/rpn_reg_loss : no so much affected by augmentation-1/2/3\n\n  - rcnn_cls_loss : augmentation-1/2 is better than augmentation-0. augmentation-2 is the best. augmentation-3 get worst\n\n  - rcnn_reg_loss : no so much affected by augmentation-1/2/3\n\n  - mask_loss : no so much affected by augmentation-1/2/3",
      "votes": null
    },
    {
      "id": "286221",
      "postDate": "02/21/2018 21:23:28",
      "content": "<p>Are you using the standard configuration that came with that model? Or are you changing some of the parameters?</p>",
      "rawMarkdown": "Are you using the standard configuration that came with that model? Or are you changing some of the parameters?",
      "votes": null
    },
    {
      "id": "286325",
      "postDate": "02/22/2018 01:43:26",
      "content": "<p>I have changed the image size mask size and rpn anchor scales from the config. I am also doing horizontal flipping and rotation as augmentation.</p>",
      "rawMarkdown": "I have changed the image size mask size and rpn anchor scales from the config. I am also doing horizontal flipping and rotation as augmentation.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 282569,
      "author_name": "mrtzmilani",
      "author_url": "",
      "post_date": "02/14/2018 07:16:54",
      "content": "<p>Did you make sure masks match the image after augmentation? And did you check not doing augmentation for test set?</p>",
      "votes": null,
      "replies": [
        {
          "id": 282634,
          "author_name": "thevivekpandey",
          "author_url": "",
          "post_date": "02/14/2018 09:45:12",
          "content": "<p>Yes, I had checked (image, mask) pairs after augmentation, and they appeared to be correct. I will check again, more throughly. </p>\n\n<p>I am not doing augmentation at test time.</p>\n\n<p>At this point I have two hypotheses:\n- Maybe I am doing augmentation incorrectly. I have visually seen (image, mask) pairs after augmentation and they seem alright, but I'll do more through checking.\n- May be, I just need to train more, since there is more data. I am currently in the process of training much more and will report if I see any boost in the score.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 282706,
      "author_name": "akilaw",
      "author_url": "",
      "post_date": "02/14/2018 12:38:39",
      "content": "<p>Are you using <a href=\"http://github.com/matterport/Mask_RCNN\">Mask RCNN</a> library to build the model? There is a random horizontal flip as augmentation I use the code with that and I was able to achieve 0.409 in the LB.</p>",
      "votes": null,
      "replies": [
        {
          "id": 282822,
          "author_name": "thevivekpandey",
          "author_url": "",
          "post_date": "02/14/2018 16:46:39",
          "content": "<p>Yes, I am using the library you referred. I know about random horizontal flip, but I wanted to add more augmentations. I have also got 0.412 with that method, but can't go beyond that even with more augmentations.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 283168,
          "author_name": "akilaw",
          "author_url": "",
          "post_date": "02/15/2018 01:34:21",
          "content": "<p>I made a submission with 90 degrees rotation horizontal and vertical flips (I used numpy functions flipud rot90 and fliplr) But it still got 0.409 and I think the issue is with detecting the color images (histology). I think we should try some of the color augmentations that Allen mentioned in his post <a href=\"https://www.kaggle.com/c/data-science-bowl-2018/discussion/48130#282959\">https://www.kaggle.com/c/data-science-bowl-2018/discussion/48130#282959</a></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 286221,
          "author_name": "panserbjorne",
          "author_url": "",
          "post_date": "02/21/2018 21:23:28",
          "content": "<p>Are you using the standard configuration that came with that model? Or are you changing some of the parameters?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 286325,
          "author_name": "akilaw",
          "author_url": "",
          "post_date": "02/22/2018 01:43:26",
          "content": "<p>I have changed the image size mask size and rpn anchor scales from the config. I am also doing horizontal flipping and rotation as augmentation.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 282946,
      "author_name": "aglotero",
      "author_url": "",
      "post_date": "02/14/2018 19:55:30",
      "content": "<p>Check if the augmented images have the same scale than the original. When I was testing some augmentation, the original images are in [0-255] range, after a resize they became floats [0-1]</p>",
      "votes": null,
      "replies": [
        {
          "id": 282951,
          "author_name": "mrtzmilani",
          "author_url": "",
          "post_date": "02/14/2018 20:00:09",
          "content": "<p>Yes, specially if one uses <code>skimage.transform.resize</code>. To avoid that, I use <code>preserve_range=True</code> option and convert the returned image to <code>uint</code>.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 282988,
          "author_name": "agoodman",
          "author_url": "",
          "post_date": "02/14/2018 20:45:05",
          "content": "<p>Yep. This is a crucial tip (and could likely be responsible for issue)!</p>\n\n<p>I’m curious, are you augmenting both your training and validation set?</p>\n\n<p><em>But it’s also worth noting that additional augmentation will require additional training (and possibly additional parameter capacity). I’d also avoid comparing augmented scores to non-augmented scores since one model is likely overfit and the other is likely underfit).</em></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 283218,
          "author_name": "thevivekpandey",
          "author_url": "",
          "post_date": "02/15/2018 04:30:35",
          "content": "<p>That's such nice tip. However, I use np.tranpose() and np.flip() to do my augmentations, so there is no chance of this phenomena.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 283271,
          "author_name": "mrtzmilani",
          "author_url": "",
          "post_date": "02/15/2018 06:16:37",
          "content": "<p>@Allen Goodman, comparing <code>train loss</code> and <code>validation loss</code> will help us to identify if the model is overfitted or not, am I right? If this is the case, we can still compare the two models.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 283390,
      "author_name": "tichyijon",
      "author_url": "",
      "post_date": "02/15/2018 12:22:36",
      "content": "<p>Can it be a result of incorrect splitting between training and validation images? </p>",
      "votes": null,
      "replies": [
        {
          "id": 283395,
          "author_name": "thevivekpandey",
          "author_url": "",
          "post_date": "02/15/2018 13:08:03",
          "content": "<p>I use one image set for training, and other for validation.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 283398,
      "author_name": "thevivekpandey",
      "author_url": "",
      "post_date": "02/15/2018 13:11:27",
      "content": "<p>By now, I have given up on making simple flip/rotation augmentations.  Maybe, it is incorrect to expect an improvement by using these augmentations: convolution filters scan over whole images and they will learn same features whether they are located in this part of the image or that part of the image. </p>\n\n<p>Perhaps augmentations like zoom/crop/brightness/noise will help, but not simple rotation and flip.</p>\n\n<p>If someone finds their scores improved by rotation/flip, kindly let me know.</p>\n\n<p>Thanks,\nVivek</p>",
      "votes": null,
      "replies": [
        {
          "id": 283871,
          "author_name": "hengck23",
          "author_url": "",
          "post_date": "02/16/2018 05:22:31",
          "content": "<p>i haven't try LB submission yet. My experiments showed better results for validation loss as follows:</p>\n\n<p>.</p>\n\n<p>augmentation-0:  no augmentation</p>\n\n<p>augmentation-1: horizontal-flip, vertical-flip, various 90-degree rotation</p>\n\n<p>augmentation-2: augmentation-1 and scale/shift/rotate</p>\n\n<p>augmentation-3: augmentation-1 and contrast/brightness shift</p>\n\n<p>.</p>\n\n<p>in mask-rcnn, there are 4 loss:</p>\n\n<ul>\n<li><p>rpn_cls_loss/rpn_reg_loss : no so much affected by augmentation-1/2/3</p></li>\n<li><p>rcnn_cls_loss : augmentation-1/2 is better than augmentation-0. augmentation-2 is the best. augmentation-3 get worst</p></li>\n<li><p>rcnn_reg_loss : no so much affected by augmentation-1/2/3</p></li>\n<li><p>mask_loss : no so much affected by augmentation-1/2/3</p></li>\n</ul>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "282566": "I have been trying to make data augmentation work for a long time, but it has repeatedly hurt my LB score. The way I do augmentation is following: For each (image, list of masks) pair,  I generate 8 (image, list of masks) pairs by rotating the image and masks by 90, 180 and 270 degrees, flipping horizontally, flipping vertically and combining these operations to generate 8 different possibilities (A square has eight symmetries).\n\nHowever, my LB score always drops when I use augmentation. FWIW I am using Mask RCNN. Has anyone else faced a similar problem?\n\nI initially suspected that I may be doing augmentation incorrectly, but I have checked augmented image and masks: they seem to be alright.",
    "282569": "Did you make sure masks match the image after augmentation? And did you check not doing augmentation for test set?",
    "282634": "Yes, I had checked (image, mask) pairs after augmentation, and they appeared to be correct. I will check again, more throughly. \n\nI am not doing augmentation at test time.\n\nAt this point I have two hypotheses:\n- Maybe I am doing augmentation incorrectly. I have visually seen (image, mask) pairs after augmentation and they seem alright, but I'll do more through checking.\n- May be, I just need to train more, since there is more data. I am currently in the process of training much more and will report if I see any boost in the score.",
    "282706": "Are you using [Mask RCNN][1] library to build the model? There is a random horizontal flip as augmentation I use the code with that and I was able to achieve 0.409 in the LB.\n\n  [1]: http://github.com/matterport/Mask_RCNN",
    "282822": "Yes, I am using the library you referred. I know about random horizontal flip, but I wanted to add more augmentations. I have also got 0.412 with that method, but can't go beyond that even with more augmentations.",
    "282946": "Check if the augmented images have the same scale than the original. When I was testing some augmentation, the original images are in [0-255] range, after a resize they became floats [0-1]",
    "282951": "Yes, specially if one uses `skimage.transform.resize`. To avoid that, I use `preserve_range=True` option and convert the returned image to `uint`.",
    "282988": "Yep. This is a crucial tip (and could likely be responsible for issue)!\n\nI’m curious, are you augmenting both your training and validation set?\n\n*But it’s also worth noting that additional augmentation will require additional training (and possibly additional parameter capacity). I’d also avoid comparing augmented scores to non-augmented scores since one model is likely overfit and the other is likely underfit).*",
    "283168": "I made a submission with 90 degrees rotation horizontal and vertical flips (I used numpy functions flipud rot90 and fliplr) But it still got 0.409 and I think the issue is with detecting the color images (histology). I think we should try some of the color augmentations that Allen mentioned in his post https://www.kaggle.com/c/data-science-bowl-2018/discussion/48130#282959",
    "283218": "That's such nice tip. However, I use np.tranpose() and np.flip() to do my augmentations, so there is no chance of this phenomena.",
    "283271": "Allen Goodman, comparing `train loss` and `validation loss` will help us to identify if the model is overfitted or not, am I right? If this is the case, we can still compare the two models.",
    "283390": "Can it be a result of incorrect splitting between training and validation images?",
    "283395": "I use one image set for training, and other for validation.",
    "283398": "By now, I have given up on making simple flip/rotation augmentations.  Maybe, it is incorrect to expect an improvement by using these augmentations: convolution filters scan over whole images and they will learn same features whether they are located in this part of the image or that part of the image. \n\nPerhaps augmentations like zoom/crop/brightness/noise will help, but not simple rotation and flip.\n\nIf someone finds their scores improved by rotation/flip, kindly let me know.\n\nThanks,\nVivek",
    "283871": "i haven't try LB submission yet. My experiments showed better results for validation loss as follows:\n\n.\n\naugmentation-0:  no augmentation\n\naugmentation-1: horizontal-flip, vertical-flip, various 90-degree rotation\n\naugmentation-2: augmentation-1 and scale/shift/rotate\n\naugmentation-3: augmentation-1 and contrast/brightness shift\n\n.\n\n\nin mask-rcnn, there are 4 loss:\n\n  - rpn_cls_loss/rpn_reg_loss : no so much affected by augmentation-1/2/3\n\n  - rcnn_cls_loss : augmentation-1/2 is better than augmentation-0. augmentation-2 is the best. augmentation-3 get worst\n\n  - rcnn_reg_loss : no so much affected by augmentation-1/2/3\n\n  - mask_loss : no so much affected by augmentation-1/2/3",
    "286221": "Are you using the standard configuration that came with that model? Or are you changing some of the parameters?",
    "286325": "I have changed the image size mask size and rpn anchor scales from the config. I am also doing horizontal flipping and rotation as augmentation."
  },
  "source": "meta"
}