{
  "id": 164989,
  "title": "Image Normalization",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/164989",
  "author_name": "",
  "post_date": "2020-07-08T05:48:59.682231500Z",
  "votes": 2,
  "comment_count": 6,
  "views": 0,
  "content": "<p>For those of you using EfficientNet or some other pre-trained model, that typically suggest parameters to use for normalization based on what the model was trained at.  Ex: for EffiicentNet it is recommended to use    <code>transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])</code> as this is what was used when it was trained on ImageNet.</p>\n\n<p>Have you noticed that using this normalization the Images are very overexposed? Here is an example:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F69253%2Fdd79e85359b6f7145f2ff5daeb396fbd%2FScreen%20Shot%202020-07-08%20at%201.45.27%20AM.png?generation=1594187301475662&amp;alt=media\" alt=\"\"></p>\n\n<p>I worry that so many of the values are so high in intensity that it may make it difficult for the Classifier, it certainly doesn't look good when browsing.</p>",
  "messages": [
    {
      "id": "919808",
      "postDate": "07/08/2020 05:48:59",
      "content": "<p>For those of you using EfficientNet or some other pre-trained model, that typically suggest parameters to use for normalization based on what the model was trained at.  Ex: for EffiicentNet it is recommended to use    <code>transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])</code> as this is what was used when it was trained on ImageNet.</p>\n\n<p>Have you noticed that using this normalization the Images are very overexposed? Here is an example:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F69253%2Fdd79e85359b6f7145f2ff5daeb396fbd%2FScreen%20Shot%202020-07-08%20at%201.45.27%20AM.png?generation=1594187301475662&amp;alt=media\" alt=\"\"></p>\n\n<p>I worry that so many of the values are so high in intensity that it may make it difficult for the Classifier, it certainly doesn't look good when browsing.</p>",
      "rawMarkdown": "For those of you using EfficientNet or some other pre-trained model, that typically suggest parameters to use for normalization based on what the model was trained at.  Ex: for EffiicentNet it is recommended to use    ` transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])` as this is what was used when it was trained on ImageNet.\n\nHave you noticed that using this normalization the Images are very overexposed? Here is an example:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F69253%2Fdd79e85359b6f7145f2ff5daeb396fbd%2FScreen%20Shot%202020-07-08%20at%201.45.27%20AM.png?generation=1594187301475662&amp;alt=media)\n\nI worry that so many of the values are so high in intensity that it may make it difficult for the Classifier, it certainly doesn't look good when browsing.",
      "votes": null
    },
    {
      "id": "919932",
      "postDate": "07/08/2020 07:51:33",
      "content": "<p><a href=\"/brianfeeny\">@brianfeeny</a> Some of your images are actually not high in intensity - 2nd and 4th image in first row above.</p>\n\n<p>Can you pls verify if may be some of your Augmentations (Random Brightness, Random Sunflare, Color Constancy, etc) might be contributing to this?</p>",
      "rawMarkdown": "brianfeeny Some of your images are actually not high in intensity - 2nd and 4th image in first row above.\n\nCan you pls verify if may be some of your Augmentations (Random Brightness, Random Sunflare, Color Constancy, etc) might be contributing to this?",
      "votes": null
    },
    {
      "id": "920057",
      "postDate": "07/08/2020 09:20:08",
      "content": "<p>Hi <a href=\"/brianfeeny\">@brianfeeny</a> those normalisation parameters are intended to centre the imagenet data at its mean and reduce its std error to 1.0\nThat is for statistical purpose only and helps the optimiser balance the gradients magnitudes (thought it isn't super important with the current pipelines and models with batchnorm)</p>\n\n<p>It isn't designed for visualisation, so some frameworks have utilities to help with that. \nE.g. torchvision.utils.vutils has a parameter <code>normalize=True</code> that actually brings the images back to [0-1] (or [0-255]) \nexample at cell 12 here: <a href=\"https://www.kaggle.com/hmendonca/melanoma-neat-pytorch-lightning-native-amp#Model\">https://www.kaggle.com/hmendonca/melanoma-neat-pytorch-lightning-native-amp#Model</a></p>",
      "rawMarkdown": "Hi @brianfeeny those normalisation parameters are intended to centre the imagenet data at its mean and reduce its std error to 1.0\nThat is for statistical purpose only and helps the optimiser balance the gradients magnitudes (thought it isn't super important with the current pipelines and models with batchnorm)\n\nIt isn't designed for visualisation, so some frameworks have utilities to help with that. \nE.g. torchvision.utils.vutils has a parameter `normalize=True` that actually brings the images back to [0-1] (or [0-255]) \nexample at cell 12 here: https://www.kaggle.com/hmendonca/melanoma-neat-pytorch-lightning-native-amp#Model",
      "votes": null
    },
    {
      "id": "920871",
      "postDate": "07/08/2020 21:32:22",
      "content": "<p>Thanks for asking.  No its purely the normalization.  Its true I am doing ALOT of transforms.  But I have tested by turning them all off.  If I set my normalization to:</p>\n\n<p><code>\n        transforms.Normalize(mean=[0.5, 0.5, 0.5],std=[0.5, 0.5, 0.5])\n</code></p>\n\n<p>Everything looks just fine.  I import the image into CV2 and then just change it to RGB and from the normalization I use for EfficientNet trained on ImageNet seems to wash out a lot.  So I am using those parameters when training as it seems that is ideal for a model trained with ImageNet, however when I do my previews of transformations I am switching to what I pasted above as its easier to see whats going on.   </p>\n\n<p>I worry though, I mean, once pixels clip, a lot of information is lost.  You could have pixels that show shapes and features, but if you push all those to 1 (or 255) then you have lost features.  </p>",
      "rawMarkdown": "Thanks for asking.  No its purely the normalization.  Its true I am doing ALOT of transforms.  But I have tested by turning them all off.  If I set my normalization to:\n\n```\n        transforms.Normalize(mean=[0.5, 0.5, 0.5],std=[0.5, 0.5, 0.5])\n```\n\nEverything looks just fine.  I import the image into CV2 and then just change it to RGB and from the normalization I use for EfficientNet trained on ImageNet seems to wash out a lot.  So I am using those parameters when training as it seems that is ideal for a model trained with ImageNet, however when I do my previews of transformations I am switching to what I pasted above as its easier to see whats going on.   \n\nI worry though, I mean, once pixels clip, a lot of information is lost.  You could have pixels that show shapes and features, but if you push all those to 1 (or 255) then you have lost features.",
      "votes": null
    },
    {
      "id": "920893",
      "postDate": "07/08/2020 22:13:18",
      "content": "<p>A side note: has anyone unequivocally shown any fixed mean/std normalization is needed at all? I never saw any performance improvements with them so I usually just turn them off completely. \nOne more parameter less to worry about.</p>",
      "rawMarkdown": "A side note: has anyone unequivocally shown any fixed mean/std normalization is needed at all? I never saw any performance improvements with them so I usually just turn them off completely. \nOne more parameter less to worry about.",
      "votes": null
    },
    {
      "id": "921296",
      "postDate": "07/09/2020 07:28:22",
      "content": "<p>Well nothing is clipped before going inside your network, just standard scaled. I guess the clipping might happen when you try to plot your normalized image no?</p>",
      "rawMarkdown": "Well nothing is clipped before going inside your network, just standard scaled. I guess the clipping might happen when you try to plot your normalized image no?",
      "votes": null
    },
    {
      "id": "921420",
      "postDate": "07/09/2020 09:00:12",
      "content": "<p>Definitely.  You can train your model with no transformations and note the score.  Then just add the ImageNet normalization’s and you will see a substantial difference.  </p>",
      "rawMarkdown": "Definitely.  You can train your model with no transformations and note the score.  Then just add the ImageNet normalization’s and you will see a substantial difference.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 919932,
      "author_name": "sirishks",
      "author_url": "",
      "post_date": "07/08/2020 07:51:33",
      "content": "<p><a href=\"/brianfeeny\">@brianfeeny</a> Some of your images are actually not high in intensity - 2nd and 4th image in first row above.</p>\n\n<p>Can you pls verify if may be some of your Augmentations (Random Brightness, Random Sunflare, Color Constancy, etc) might be contributing to this?</p>",
      "votes": null,
      "replies": [
        {
          "id": 920871,
          "author_name": "brianfeeny",
          "author_url": "",
          "post_date": "07/08/2020 21:32:22",
          "content": "<p>Thanks for asking.  No its purely the normalization.  Its true I am doing ALOT of transforms.  But I have tested by turning them all off.  If I set my normalization to:</p>\n\n<p><code>\n        transforms.Normalize(mean=[0.5, 0.5, 0.5],std=[0.5, 0.5, 0.5])\n</code></p>\n\n<p>Everything looks just fine.  I import the image into CV2 and then just change it to RGB and from the normalization I use for EfficientNet trained on ImageNet seems to wash out a lot.  So I am using those parameters when training as it seems that is ideal for a model trained with ImageNet, however when I do my previews of transformations I am switching to what I pasted above as its easier to see whats going on.   </p>\n\n<p>I worry though, I mean, once pixels clip, a lot of information is lost.  You could have pixels that show shapes and features, but if you push all those to 1 (or 255) then you have lost features.  </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 921296,
          "author_name": "optimo",
          "author_url": "",
          "post_date": "07/09/2020 07:28:22",
          "content": "<p>Well nothing is clipped before going inside your network, just standard scaled. I guess the clipping might happen when you try to plot your normalized image no?</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 920057,
      "author_name": "hmendonca",
      "author_url": "",
      "post_date": "07/08/2020 09:20:08",
      "content": "<p>Hi <a href=\"/brianfeeny\">@brianfeeny</a> those normalisation parameters are intended to centre the imagenet data at its mean and reduce its std error to 1.0\nThat is for statistical purpose only and helps the optimiser balance the gradients magnitudes (thought it isn't super important with the current pipelines and models with batchnorm)</p>\n\n<p>It isn't designed for visualisation, so some frameworks have utilities to help with that. \nE.g. torchvision.utils.vutils has a parameter <code>normalize=True</code> that actually brings the images back to [0-1] (or [0-255]) \nexample at cell 12 here: <a href=\"https://www.kaggle.com/hmendonca/melanoma-neat-pytorch-lightning-native-amp#Model\">https://www.kaggle.com/hmendonca/melanoma-neat-pytorch-lightning-native-amp#Model</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 920893,
      "author_name": "tschandl",
      "author_url": "",
      "post_date": "07/08/2020 22:13:18",
      "content": "<p>A side note: has anyone unequivocally shown any fixed mean/std normalization is needed at all? I never saw any performance improvements with them so I usually just turn them off completely. \nOne more parameter less to worry about.</p>",
      "votes": null,
      "replies": [
        {
          "id": 921420,
          "author_name": "brianfeeny",
          "author_url": "",
          "post_date": "07/09/2020 09:00:12",
          "content": "<p>Definitely.  You can train your model with no transformations and note the score.  Then just add the ImageNet normalization’s and you will see a substantial difference.  </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "919808": "For those of you using EfficientNet or some other pre-trained model, that typically suggest parameters to use for normalization based on what the model was trained at.  Ex: for EffiicentNet it is recommended to use    ` transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])` as this is what was used when it was trained on ImageNet.\n\nHave you noticed that using this normalization the Images are very overexposed? Here is an example:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F69253%2Fdd79e85359b6f7145f2ff5daeb396fbd%2FScreen%20Shot%202020-07-08%20at%201.45.27%20AM.png?generation=1594187301475662&amp;alt=media)\n\nI worry that so many of the values are so high in intensity that it may make it difficult for the Classifier, it certainly doesn't look good when browsing.",
    "919932": "brianfeeny Some of your images are actually not high in intensity - 2nd and 4th image in first row above.\n\nCan you pls verify if may be some of your Augmentations (Random Brightness, Random Sunflare, Color Constancy, etc) might be contributing to this?",
    "920057": "Hi @brianfeeny those normalisation parameters are intended to centre the imagenet data at its mean and reduce its std error to 1.0\nThat is for statistical purpose only and helps the optimiser balance the gradients magnitudes (thought it isn't super important with the current pipelines and models with batchnorm)\n\nIt isn't designed for visualisation, so some frameworks have utilities to help with that. \nE.g. torchvision.utils.vutils has a parameter `normalize=True` that actually brings the images back to [0-1] (or [0-255]) \nexample at cell 12 here: https://www.kaggle.com/hmendonca/melanoma-neat-pytorch-lightning-native-amp#Model",
    "920871": "Thanks for asking.  No its purely the normalization.  Its true I am doing ALOT of transforms.  But I have tested by turning them all off.  If I set my normalization to:\n\n```\n        transforms.Normalize(mean=[0.5, 0.5, 0.5],std=[0.5, 0.5, 0.5])\n```\n\nEverything looks just fine.  I import the image into CV2 and then just change it to RGB and from the normalization I use for EfficientNet trained on ImageNet seems to wash out a lot.  So I am using those parameters when training as it seems that is ideal for a model trained with ImageNet, however when I do my previews of transformations I am switching to what I pasted above as its easier to see whats going on.   \n\nI worry though, I mean, once pixels clip, a lot of information is lost.  You could have pixels that show shapes and features, but if you push all those to 1 (or 255) then you have lost features.",
    "920893": "A side note: has anyone unequivocally shown any fixed mean/std normalization is needed at all? I never saw any performance improvements with them so I usually just turn them off completely. \nOne more parameter less to worry about.",
    "921296": "Well nothing is clipped before going inside your network, just standard scaled. I guess the clipping might happen when you try to plot your normalized image no?",
    "921420": "Definitely.  You can train your model with no transformations and note the score.  Then just add the ImageNet normalization’s and you will see a substantial difference."
  },
  "source": "meta"
}