{
  "id": 100755,
  "title": "Image normalization for pre-trained models",
  "url": "/competitions/recursion-cellular-image-classification/discussion/100755",
  "author_name": "",
  "post_date": "2019-07-20T17:53:52.704527400Z",
  "votes": 9,
  "comment_count": 7,
  "views": 0,
  "content": "<p>Before starting to experiments with new architectures and training from scratch, I'd like to get a decent score using pre-trained models (e.g., ResNet34 and DenseNet). Unfortunately, my attempts so far have all failed.</p>\n\n<p>Two things I'm not sure I'm doing right, are normalization and the way I pass the images to the network. Regarding the latter, I simply define a new first convolutional layer that takes the 6 channels as input. I'm training it from scratch.\nRegarding the normalization, I simply use the statistics from RxRx. The problem is that models like ResNet were trained with RGB images, so although it's technically possible to do this, I do not know whether it's correct.</p>\n\n<p>I tried to train ResNet34 both from scratch and using a pre-trained model. Sadly, the performances of both are comparable and I obtain very low accuracies. Something I did not expect, also considering that others are using the same model and are obtaining much higher accuracies!</p>\n\n<p>One more thing I'm worried about, is batch size. My machine (GTX 1060), with ResNet34, 6 channels and 128x128 images cannot use a batch size larger than 16. Is it too small?</p>\n\n<p>Does anybody have any suggestion regarding both input normalization and how to handle 6 channels rather than RGB images?</p>",
  "messages": [
    {
      "id": "580765",
      "postDate": "07/20/2019 17:53:52",
      "content": "<p>Before starting to experiments with new architectures and training from scratch, I'd like to get a decent score using pre-trained models (e.g., ResNet34 and DenseNet). Unfortunately, my attempts so far have all failed.</p>\n\n<p>Two things I'm not sure I'm doing right, are normalization and the way I pass the images to the network. Regarding the latter, I simply define a new first convolutional layer that takes the 6 channels as input. I'm training it from scratch.\nRegarding the normalization, I simply use the statistics from RxRx. The problem is that models like ResNet were trained with RGB images, so although it's technically possible to do this, I do not know whether it's correct.</p>\n\n<p>I tried to train ResNet34 both from scratch and using a pre-trained model. Sadly, the performances of both are comparable and I obtain very low accuracies. Something I did not expect, also considering that others are using the same model and are obtaining much higher accuracies!</p>\n\n<p>One more thing I'm worried about, is batch size. My machine (GTX 1060), with ResNet34, 6 channels and 128x128 images cannot use a batch size larger than 16. Is it too small?</p>\n\n<p>Does anybody have any suggestion regarding both input normalization and how to handle 6 channels rather than RGB images?</p>",
      "rawMarkdown": "Before starting to experiments with new architectures and training from scratch, I'd like to get a decent score using pre-trained models (e.g., ResNet34 and DenseNet). Unfortunately, my attempts so far have all failed.\n\nTwo things I'm not sure I'm doing right, are normalization and the way I pass the images to the network. Regarding the latter, I simply define a new first convolutional layer that takes the 6 channels as input. I'm training it from scratch.\nRegarding the normalization, I simply use the statistics from RxRx. The problem is that models like ResNet were trained with RGB images, so although it's technically possible to do this, I do not know whether it's correct.\n\nI tried to train ResNet34 both from scratch and using a pre-trained model. Sadly, the performances of both are comparable and I obtain very low accuracies. Something I did not expect, also considering that others are using the same model and are obtaining much higher accuracies!\n\nOne more thing I'm worried about, is batch size. My machine (GTX 1060), with ResNet34, 6 channels and 128x128 images cannot use a batch size larger than 16. Is it too small?\n\nDoes anybody have any suggestion regarding both input normalization and how to handle 6 channels rather than RGB images?",
      "votes": null
    },
    {
      "id": "590833",
      "postDate": "08/02/2019 17:10:48",
      "content": "<p>Sorry, how have you normalized your images? Can you explaine please? How should we use pixel_stats.csv? Thanks.</p>",
      "rawMarkdown": "Sorry, how have you normalized your images? Can you explaine please? How should we use pixel_stats.csv? Thanks.",
      "votes": null
    },
    {
      "id": "590852",
      "postDate": "08/02/2019 17:54:16",
      "content": "<p><a href=\"/joven1997\">@joven1997</a> I simply took the means and standard deviations from <a href=\"https://github.com/recursionpharma/rxrx1-utils/blob/master/rxrx/main.py\">here</a> and then I used <code>Normalize</code> from PyTorch. I did not use pixel_stats.csv.</p>",
      "rawMarkdown": "joven1997 I simply took the means and standard deviations from [here](https://github.com/recursionpharma/rxrx1-utils/blob/master/rxrx/main.py) and then I used `Normalize` from PyTorch. I did not use pixel_stats.csv.",
      "votes": null
    },
    {
      "id": "590869",
      "postDate": "08/02/2019 18:18:11",
      "content": "<p>Thanks! </p>",
      "rawMarkdown": "Thanks!",
      "votes": null
    },
    {
      "id": "593448",
      "postDate": "08/06/2019 16:08:04",
      "content": "<p><a href=\"/lorenzofabbri92\">@lorenzofabbri92</a> did you normalize before applying ToTensor or after it?</p>",
      "rawMarkdown": "lorenzofabbri92 did you normalize before applying ToTensor or after it?",
      "votes": null
    },
    {
      "id": "593452",
      "postDate": "08/06/2019 16:10:13",
      "content": "<p>I'm not using <code>ToTensor</code> since the output of my <code>Dataset</code> is a tensor already.</p>",
      "rawMarkdown": "I'm not using `ToTensor` since the output of my `Dataset` is a tensor already.",
      "votes": null
    },
    {
      "id": "593523",
      "postDate": "08/06/2019 18:13:18",
      "content": "<p>And in what range your pixel values are on the output of your <code>Dataset</code> ? [0,255] or [0,1] ?</p>",
      "rawMarkdown": "And in what range your pixel values are on the output of your ```Dataset``` ? [0,255] or [0,1] ?",
      "votes": null
    },
    {
      "id": "593739",
      "postDate": "08/07/2019 03:19:29",
      "content": "<p><a href=\"/rafailfridman\">@rafailfridman</a> Well, in neither of those... I guess it depends on the input to <code>ToTensor</code>.</p>",
      "rawMarkdown": "rafailfridman Well, in neither of those... I guess it depends on the input to `ToTensor`.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 590833,
      "author_name": "joven1997",
      "author_url": "",
      "post_date": "08/02/2019 17:10:48",
      "content": "<p>Sorry, how have you normalized your images? Can you explaine please? How should we use pixel_stats.csv? Thanks.</p>",
      "votes": null,
      "replies": [
        {
          "id": 590852,
          "author_name": "lorenzofabbri92",
          "author_url": "",
          "post_date": "08/02/2019 17:54:16",
          "content": "<p><a href=\"/joven1997\">@joven1997</a> I simply took the means and standard deviations from <a href=\"https://github.com/recursionpharma/rxrx1-utils/blob/master/rxrx/main.py\">here</a> and then I used <code>Normalize</code> from PyTorch. I did not use pixel_stats.csv.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 590869,
          "author_name": "joven1997",
          "author_url": "",
          "post_date": "08/02/2019 18:18:11",
          "content": "<p>Thanks! </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 593448,
      "author_name": "rafailfridman",
      "author_url": "",
      "post_date": "08/06/2019 16:08:04",
      "content": "<p><a href=\"/lorenzofabbri92\">@lorenzofabbri92</a> did you normalize before applying ToTensor or after it?</p>",
      "votes": null,
      "replies": [
        {
          "id": 593452,
          "author_name": "lorenzofabbri92",
          "author_url": "",
          "post_date": "08/06/2019 16:10:13",
          "content": "<p>I'm not using <code>ToTensor</code> since the output of my <code>Dataset</code> is a tensor already.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 593523,
          "author_name": "rafailfridman",
          "author_url": "",
          "post_date": "08/06/2019 18:13:18",
          "content": "<p>And in what range your pixel values are on the output of your <code>Dataset</code> ? [0,255] or [0,1] ?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 593739,
          "author_name": "lorenzofabbri92",
          "author_url": "",
          "post_date": "08/07/2019 03:19:29",
          "content": "<p><a href=\"/rafailfridman\">@rafailfridman</a> Well, in neither of those... I guess it depends on the input to <code>ToTensor</code>.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "580765": "Before starting to experiments with new architectures and training from scratch, I'd like to get a decent score using pre-trained models (e.g., ResNet34 and DenseNet). Unfortunately, my attempts so far have all failed.\n\nTwo things I'm not sure I'm doing right, are normalization and the way I pass the images to the network. Regarding the latter, I simply define a new first convolutional layer that takes the 6 channels as input. I'm training it from scratch.\nRegarding the normalization, I simply use the statistics from RxRx. The problem is that models like ResNet were trained with RGB images, so although it's technically possible to do this, I do not know whether it's correct.\n\nI tried to train ResNet34 both from scratch and using a pre-trained model. Sadly, the performances of both are comparable and I obtain very low accuracies. Something I did not expect, also considering that others are using the same model and are obtaining much higher accuracies!\n\nOne more thing I'm worried about, is batch size. My machine (GTX 1060), with ResNet34, 6 channels and 128x128 images cannot use a batch size larger than 16. Is it too small?\n\nDoes anybody have any suggestion regarding both input normalization and how to handle 6 channels rather than RGB images?",
    "590833": "Sorry, how have you normalized your images? Can you explaine please? How should we use pixel_stats.csv? Thanks.",
    "590852": "joven1997 I simply took the means and standard deviations from [here](https://github.com/recursionpharma/rxrx1-utils/blob/master/rxrx/main.py) and then I used `Normalize` from PyTorch. I did not use pixel_stats.csv.",
    "590869": "Thanks!",
    "593448": "lorenzofabbri92 did you normalize before applying ToTensor or after it?",
    "593452": "I'm not using `ToTensor` since the output of my `Dataset` is a tensor already.",
    "593523": "And in what range your pixel values are on the output of your ```Dataset``` ? [0,255] or [0,1] ?",
    "593739": "rafailfridman Well, in neither of those... I guess it depends on the input to `ToTensor`."
  },
  "source": "meta"
}