{
  "id": 219588,
  "title": "Image Resolution and Accuracy",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/219588",
  "author_name": "",
  "post_date": "2021-02-15T15:11:07.464876600Z",
  "votes": 7,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I'm using an efficient net b3 backbone with an Image size of 256x256 it achieves accuracy of somewhere around 0.85 </p>\n<p>but using image resolution of 512x512 accuracy dips significantly to 0.65</p>\n<p>(PS. due to the large image size, I need to reduce the batch size while training model with 512x512 size)</p>\n<p>I was assuming that accuracy should increase or must be somewhere around 256x256</p>\n<p>Any particular reason for the above failure<br>\nAlso, it would be nice if you can mention your CV or LB score </p>",
  "messages": [
    {
      "id": "1201680",
      "postDate": "02/15/2021 15:11:07",
      "content": "<p>I'm using an efficient net b3 backbone with an Image size of 256x256 it achieves accuracy of somewhere around 0.85 </p>\n<p>but using image resolution of 512x512 accuracy dips significantly to 0.65</p>\n<p>(PS. due to the large image size, I need to reduce the batch size while training model with 512x512 size)</p>\n<p>I was assuming that accuracy should increase or must be somewhere around 256x256</p>\n<p>Any particular reason for the above failure<br>\nAlso, it would be nice if you can mention your CV or LB score </p>",
      "rawMarkdown": "I'm using an efficient net b3 backbone with an Image size of 256x256 it achieves accuracy of somewhere around 0.85 \n\nbut using image resolution of 512x512 accuracy dips significantly to 0.65\n\n(PS. due to the large image size, I need to reduce the batch size while training model with 512x512 size)\n\nI was assuming that accuracy should increase or must be somewhere around 256x256\n\nAny particular reason for the above failure\nAlso, it would be nice if you can mention your CV or LB score",
      "votes": null
    },
    {
      "id": "1201757",
      "postDate": "02/15/2021 16:23:37",
      "content": "<p>Hello!</p>\n<p>I'm sure there must be a mistake in your code, as numerous users here reported that larger image size, ceteris paribus, leads to higher accuracy. To make your experiments with image size clear, make sure that you seed every operation including randomness in your code and manually initialize the model's head. </p>\n<p>One of the reasons for this accuracy drop is the learning rate which, generally speaking, should not be kept the same if you change the batch size: smaller batches mean more stochasticity while larger batches are more stable. A rule of thumb I've seen throughout many notebooks is setting the max value of the learning rate equal to <code>3e-5 - 1e-4</code> times the number of cores (GPU = 1 core, TPU = 8 cores) when you fine-tuning or to <code>0.1 * batch_size / 256</code> when you are training from scratch.</p>\n<p>As for me, switching from 384x384 to 512x512 resulted in +0.03 CV &amp; LB gain.</p>",
      "rawMarkdown": "Hello!\n\nI'm sure there must be a mistake in your code, as numerous users here reported that larger image size, ceteris paribus, leads to higher accuracy. To make your experiments with image size clear, make sure that you seed every operation including randomness in your code and manually initialize the model's head. \n\nOne of the reasons for this accuracy drop is the learning rate which, generally speaking, should not be kept the same if you change the batch size: smaller batches mean more stochasticity while larger batches are more stable. A rule of thumb I've seen throughout many notebooks is setting the max value of the learning rate equal to `3e-5 - 1e-4` times the number of cores (GPU = 1 core, TPU = 8 cores) when you fine-tuning or to `0.1 * batch_size / 256` when you are training from scratch.\n\nAs for me, switching from 384x384 to 512x512 resulted in +0.03 CV & LB gain.",
      "votes": null
    },
    {
      "id": "1201839",
      "postDate": "02/15/2021 17:24:39",
      "content": "<p>I noticed an improvement on B3 with a bigger image size, so I would check our code and print out the image shape during training to make sure some augments are not causing the image size to be something other than what you wanted. </p>",
      "rawMarkdown": "I noticed an improvement on B3 with a bigger image size, so I would check our code and print out the image shape during training to make sure some augments are not causing the image size to be something other than what you wanted.",
      "votes": null
    },
    {
      "id": "1202089",
      "postDate": "02/15/2021 20:35:37",
      "content": "<p>I am using 512 size and it worked best. 256 size is giving less accuracy. You must have made a mistake somewhere. <br>\nIf it is helpful you can compare it with my basic notebooks <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/216461\" target=\"_blank\">here</a></p>",
      "rawMarkdown": "I am using 512 size and it worked best. 256 size is giving less accuracy. You must have made a mistake somewhere. \nIf it is helpful you can compare it with my basic notebooks [here](https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/216461)",
      "votes": null
    },
    {
      "id": "1204181",
      "postDate": "02/15/2021 22:45:38",
      "content": "<p>Most pretrained image neural networks have BatchNormalizations. So if you have a very small batch size, then when you finetune the BatchNormalizations you are using a very small sample amount to estimate mean and variance. Maybe look into gradient accumulation. Also Learning Rate must be tuned mutually with Batch size.</p>",
      "rawMarkdown": "Most pretrained image neural networks have BatchNormalizations. So if you have a very small batch size, then when you finetune the BatchNormalizations you are using a very small sample amount to estimate mean and variance. Maybe look into gradient accumulation. Also Learning Rate must be tuned mutually with Batch size.",
      "votes": null
    },
    {
      "id": "1204308",
      "postDate": "02/16/2021 03:42:05",
      "content": "<p>You can try different learning rate schedules. Like cosine annealing or exponential decay and see if the CV improves. Also when applying the learning rate schedules, don't use early stopping because it may stop training before the accuracy is improved.</p>",
      "rawMarkdown": "You can try different learning rate schedules. Like cosine annealing or exponential decay and see if the CV improves. Also when applying the learning rate schedules, don't use early stopping because it may stop training before the accuracy is improved.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1201757,
      "author_name": "nickuzmenkov",
      "author_url": "",
      "post_date": "02/15/2021 16:23:37",
      "content": "<p>Hello!</p>\n<p>I'm sure there must be a mistake in your code, as numerous users here reported that larger image size, ceteris paribus, leads to higher accuracy. To make your experiments with image size clear, make sure that you seed every operation including randomness in your code and manually initialize the model's head. </p>\n<p>One of the reasons for this accuracy drop is the learning rate which, generally speaking, should not be kept the same if you change the batch size: smaller batches mean more stochasticity while larger batches are more stable. A rule of thumb I've seen throughout many notebooks is setting the max value of the learning rate equal to <code>3e-5 - 1e-4</code> times the number of cores (GPU = 1 core, TPU = 8 cores) when you fine-tuning or to <code>0.1 * batch_size / 256</code> when you are training from scratch.</p>\n<p>As for me, switching from 384x384 to 512x512 resulted in +0.03 CV &amp; LB gain.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1201839,
      "author_name": "trushk",
      "author_url": "",
      "post_date": "02/15/2021 17:24:39",
      "content": "<p>I noticed an improvement on B3 with a bigger image size, so I would check our code and print out the image shape during training to make sure some augments are not causing the image size to be something other than what you wanted. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1202089,
      "author_name": "vickygoyal",
      "author_url": "",
      "post_date": "02/15/2021 20:35:37",
      "content": "<p>I am using 512 size and it worked best. 256 size is giving less accuracy. You must have made a mistake somewhere. <br>\nIf it is helpful you can compare it with my basic notebooks <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/216461\" target=\"_blank\">here</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1204181,
      "author_name": "returnofsputnik",
      "author_url": "",
      "post_date": "02/15/2021 22:45:38",
      "content": "<p>Most pretrained image neural networks have BatchNormalizations. So if you have a very small batch size, then when you finetune the BatchNormalizations you are using a very small sample amount to estimate mean and variance. Maybe look into gradient accumulation. Also Learning Rate must be tuned mutually with Batch size.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1204308,
      "author_name": "sigmasix",
      "author_url": "",
      "post_date": "02/16/2021 03:42:05",
      "content": "<p>You can try different learning rate schedules. Like cosine annealing or exponential decay and see if the CV improves. Also when applying the learning rate schedules, don't use early stopping because it may stop training before the accuracy is improved.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1201680": "I'm using an efficient net b3 backbone with an Image size of 256x256 it achieves accuracy of somewhere around 0.85 \n\nbut using image resolution of 512x512 accuracy dips significantly to 0.65\n\n(PS. due to the large image size, I need to reduce the batch size while training model with 512x512 size)\n\nI was assuming that accuracy should increase or must be somewhere around 256x256\n\nAny particular reason for the above failure\nAlso, it would be nice if you can mention your CV or LB score",
    "1201757": "Hello!\n\nI'm sure there must be a mistake in your code, as numerous users here reported that larger image size, ceteris paribus, leads to higher accuracy. To make your experiments with image size clear, make sure that you seed every operation including randomness in your code and manually initialize the model's head. \n\nOne of the reasons for this accuracy drop is the learning rate which, generally speaking, should not be kept the same if you change the batch size: smaller batches mean more stochasticity while larger batches are more stable. A rule of thumb I've seen throughout many notebooks is setting the max value of the learning rate equal to `3e-5 - 1e-4` times the number of cores (GPU = 1 core, TPU = 8 cores) when you fine-tuning or to `0.1 * batch_size / 256` when you are training from scratch.\n\nAs for me, switching from 384x384 to 512x512 resulted in +0.03 CV & LB gain.",
    "1201839": "I noticed an improvement on B3 with a bigger image size, so I would check our code and print out the image shape during training to make sure some augments are not causing the image size to be something other than what you wanted.",
    "1202089": "I am using 512 size and it worked best. 256 size is giving less accuracy. You must have made a mistake somewhere. \nIf it is helpful you can compare it with my basic notebooks [here](https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/216461)",
    "1204181": "Most pretrained image neural networks have BatchNormalizations. So if you have a very small batch size, then when you finetune the BatchNormalizations you are using a very small sample amount to estimate mean and variance. Maybe look into gradient accumulation. Also Learning Rate must be tuned mutually with Batch size.",
    "1204308": "You can try different learning rate schedules. Like cosine annealing or exponential decay and see if the CV improves. Also when applying the learning rate schedules, don't use early stopping because it may stop training before the accuracy is improved."
  },
  "source": "meta"
}