{
  "id": 316853,
  "title": "Idea for the Learning Rate Callback ",
  "url": "/competitions/happy-whale-and-dolphin/discussion/316853",
  "author_name": "",
  "post_date": "2022-04-04T08:42:51.942408900Z",
  "votes": 3,
  "comment_count": 7,
  "views": 0,
  "content": "<p>Many notebooks (in this competition) are used this function for **Learning Rate **</p>\n<pre><code>def get_lr_callback(plot=False):\n    lr_start   = 0.000001\n    lr_max     = 0.000005 * config.BATCH_SIZE  \n    lr_min     = 0.000001\n    lr_ramp_ep = 4\n    lr_sus_ep  = 0\n    lr_decay   = 0.9\n\n    def lrfn(epoch):\n        if config.RESUME:\n            epoch = epoch + config.RESUME_EPOCH\n        if epoch &lt; lr_ramp_ep:\n            lr = (lr_max - lr_start) / lr_ramp_ep * epoch + lr_start\n\n        elif epoch &lt; lr_ramp_ep + lr_sus_ep:\n            lr = lr_max\n\n        else:\n            lr = (lr_max - lr_min) * lr_decay**(epoch - lr_ramp_ep - lr_sus_ep) + lr_min\n\n        return lr\n\n    if plot:\n        epochs = list(range(config.EPOCHS))\n        learning_rates = [lrfn(x) for x in epochs]\n        plt.scatter(epochs,learning_rates)\n        plt.show()\n\n    lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=False)\n    return lr_callback\n\nget_lr_callback(plot=True)\n</code></pre>\n<p>I do not know when is the idea for this implementation?<br>\nAnd what is useful to EfficientNet Architecture or in larger? </p>\n<p>P/S : I try to find out the answer in comments but maybe it is not exist, please show me if you know.</p>",
  "messages": [
    {
      "id": "1744727",
      "postDate": "04/04/2022 08:42:51",
      "content": "<p>Many notebooks (in this competition) are used this function for **Learning Rate **</p>\n<pre><code>def get_lr_callback(plot=False):\n    lr_start   = 0.000001\n    lr_max     = 0.000005 * config.BATCH_SIZE  \n    lr_min     = 0.000001\n    lr_ramp_ep = 4\n    lr_sus_ep  = 0\n    lr_decay   = 0.9\n\n    def lrfn(epoch):\n        if config.RESUME:\n            epoch = epoch + config.RESUME_EPOCH\n        if epoch &lt; lr_ramp_ep:\n            lr = (lr_max - lr_start) / lr_ramp_ep * epoch + lr_start\n\n        elif epoch &lt; lr_ramp_ep + lr_sus_ep:\n            lr = lr_max\n\n        else:\n            lr = (lr_max - lr_min) * lr_decay**(epoch - lr_ramp_ep - lr_sus_ep) + lr_min\n\n        return lr\n\n    if plot:\n        epochs = list(range(config.EPOCHS))\n        learning_rates = [lrfn(x) for x in epochs]\n        plt.scatter(epochs,learning_rates)\n        plt.show()\n\n    lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=False)\n    return lr_callback\n\nget_lr_callback(plot=True)\n</code></pre>\n<p>I do not know when is the idea for this implementation?<br>\nAnd what is useful to EfficientNet Architecture or in larger? </p>\n<p>P/S : I try to find out the answer in comments but maybe it is not exist, please show me if you know.</p>",
      "rawMarkdown": "Many notebooks (in this competition) are used this function for **Learning Rate **\n```\ndef get_lr_callback(plot=False):\n    lr_start   = 0.000001\n    lr_max     = 0.000005 * config.BATCH_SIZE  \n    lr_min     = 0.000001\n    lr_ramp_ep = 4\n    lr_sus_ep  = 0\n    lr_decay   = 0.9\n   \n    def lrfn(epoch):\n        if config.RESUME:\n            epoch = epoch + config.RESUME_EPOCH\n        if epoch < lr_ramp_ep:\n            lr = (lr_max - lr_start) / lr_ramp_ep * epoch + lr_start\n            \n        elif epoch < lr_ramp_ep + lr_sus_ep:\n            lr = lr_max\n            \n        else:\n            lr = (lr_max - lr_min) * lr_decay**(epoch - lr_ramp_ep - lr_sus_ep) + lr_min\n            \n        return lr\n        \n    if plot:\n        epochs = list(range(config.EPOCHS))\n        learning_rates = [lrfn(x) for x in epochs]\n        plt.scatter(epochs,learning_rates)\n        plt.show()\n\n    lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=False)\n    return lr_callback\n\nget_lr_callback(plot=True)\n```\n\nI do not know when is the idea for this implementation?\nAnd what is useful to EfficientNet Architecture or in larger? \n\nP/S : I try to find out the answer in comments but maybe it is not exist, please show me if you know.",
      "votes": null
    },
    {
      "id": "1744735",
      "postDate": "04/04/2022 08:59:44",
      "content": "<p>This is simple <a href=\"https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html\" target=\"_blank\">ExponentialLR </a> with <a href=\"https://stackoverflow.com/questions/55933867/what-does-learning-rate-warm-up-mean\" target=\"_blank\">warmup</a>, it looks like this:<br>\n<img src=\"https://i.ibb.co/vzkWWwW/image.png\" alt=\"lr\"><br>\nIt is not the best and only scheduler for this task, just one of.</p>",
      "rawMarkdown": "This is simple [ExponentialLR ](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html) with [warmup](https://stackoverflow.com/questions/55933867/what-does-learning-rate-warm-up-mean), it looks like this:\n![lr](https://i.ibb.co/vzkWWwW/image.png)\nIt is not the best and only scheduler for this task, just one of.",
      "votes": null
    },
    {
      "id": "1745346",
      "postDate": "04/04/2022 21:10:33",
      "content": "<p>I would recommend checking out the lr scheduler in fastai, it can give a slightly better performance</p>",
      "rawMarkdown": "I would recommend checking out the lr scheduler in fastai, it can give a slightly better performance",
      "votes": null
    },
    {
      "id": "1746746",
      "postDate": "04/06/2022 04:22:24",
      "content": "<p>A lot of the code shared in the public kernels comes from the Google Collab Flowers TPU example, including the LR scheduler.</p>\n<p><a href=\"https://colab.research.google.com/notebooks/tpu.ipynb\" target=\"_blank\">https://colab.research.google.com/notebooks/tpu.ipynb</a></p>",
      "rawMarkdown": "A lot of the code shared in the public kernels comes from the Google Collab Flowers TPU example, including the LR scheduler.\n\nhttps://colab.research.google.com/notebooks/tpu.ipynb",
      "votes": null
    },
    {
      "id": "1746772",
      "postDate": "04/06/2022 04:56:29",
      "content": "<p><a href=\"https://www.kaggle.com/kwentar\" target=\"_blank\">@kwentar</a> what is your recommendation?</p>",
      "rawMarkdown": "kwentar what is your recommendation?",
      "votes": null
    },
    {
      "id": "1746873",
      "postDate": "04/06/2022 07:26:47",
      "content": "<p>for me works good <a href=\"https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingLR.html\" target=\"_blank\">CosineAnnealingLR </a> and LR <a href=\"https://fastai1.fast.ai/callbacks.one_cycle.html\" target=\"_blank\">scheduler</a> from FastAI </p>",
      "rawMarkdown": "for me works good [CosineAnnealingLR ](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingLR.html) and LR [scheduler](https://fastai1.fast.ai/callbacks.one_cycle.html) from FastAI",
      "votes": null
    },
    {
      "id": "1746885",
      "postDate": "04/06/2022 07:33:30",
      "content": "<p>and that from experience or paper, or any algorithm? <a href=\"https://www.kaggle.com/kwentar\" target=\"_blank\">@kwentar</a> </p>",
      "rawMarkdown": "and that from experience or paper, or any algorithm? @kwentar",
      "votes": null
    },
    {
      "id": "1746894",
      "postDate": "04/06/2022 07:40:50",
      "content": "<p>I mean in this competition from my experience, but fastai says it works everywhere, also <a href=\"https://arxiv.org/pdf/1803.09820.pdf\" target=\"_blank\">paper </a> about it </p>",
      "rawMarkdown": "I mean in this competition from my experience, but fastai says it works everywhere, also [paper ](https://arxiv.org/pdf/1803.09820.pdf) about it",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1744735,
      "author_name": "kwentar",
      "author_url": "",
      "post_date": "04/04/2022 08:59:44",
      "content": "<p>This is simple <a href=\"https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html\" target=\"_blank\">ExponentialLR </a> with <a href=\"https://stackoverflow.com/questions/55933867/what-does-learning-rate-warm-up-mean\" target=\"_blank\">warmup</a>, it looks like this:<br>\n<img src=\"https://i.ibb.co/vzkWWwW/image.png\" alt=\"lr\"><br>\nIt is not the best and only scheduler for this task, just one of.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1746772,
          "author_name": "remekkinas",
          "author_url": "",
          "post_date": "04/06/2022 04:56:29",
          "content": "<p><a href=\"https://www.kaggle.com/kwentar\" target=\"_blank\">@kwentar</a> what is your recommendation?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1746873,
          "author_name": "kwentar",
          "author_url": "",
          "post_date": "04/06/2022 07:26:47",
          "content": "<p>for me works good <a href=\"https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingLR.html\" target=\"_blank\">CosineAnnealingLR </a> and LR <a href=\"https://fastai1.fast.ai/callbacks.one_cycle.html\" target=\"_blank\">scheduler</a> from FastAI </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1746885,
          "author_name": "phanttan",
          "author_url": "",
          "post_date": "04/06/2022 07:33:30",
          "content": "<p>and that from experience or paper, or any algorithm? <a href=\"https://www.kaggle.com/kwentar\" target=\"_blank\">@kwentar</a> </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1746894,
          "author_name": "kwentar",
          "author_url": "",
          "post_date": "04/06/2022 07:40:50",
          "content": "<p>I mean in this competition from my experience, but fastai says it works everywhere, also <a href=\"https://arxiv.org/pdf/1803.09820.pdf\" target=\"_blank\">paper </a> about it </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1745346,
      "author_name": "init27",
      "author_url": "",
      "post_date": "04/04/2022 21:10:33",
      "content": "<p>I would recommend checking out the lr scheduler in fastai, it can give a slightly better performance</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1746746,
      "author_name": "lextoumbourou",
      "author_url": "",
      "post_date": "04/06/2022 04:22:24",
      "content": "<p>A lot of the code shared in the public kernels comes from the Google Collab Flowers TPU example, including the LR scheduler.</p>\n<p><a href=\"https://colab.research.google.com/notebooks/tpu.ipynb\" target=\"_blank\">https://colab.research.google.com/notebooks/tpu.ipynb</a></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1744727": "Many notebooks (in this competition) are used this function for **Learning Rate **\n```\ndef get_lr_callback(plot=False):\n    lr_start   = 0.000001\n    lr_max     = 0.000005 * config.BATCH_SIZE  \n    lr_min     = 0.000001\n    lr_ramp_ep = 4\n    lr_sus_ep  = 0\n    lr_decay   = 0.9\n   \n    def lrfn(epoch):\n        if config.RESUME:\n            epoch = epoch + config.RESUME_EPOCH\n        if epoch < lr_ramp_ep:\n            lr = (lr_max - lr_start) / lr_ramp_ep * epoch + lr_start\n            \n        elif epoch < lr_ramp_ep + lr_sus_ep:\n            lr = lr_max\n            \n        else:\n            lr = (lr_max - lr_min) * lr_decay**(epoch - lr_ramp_ep - lr_sus_ep) + lr_min\n            \n        return lr\n        \n    if plot:\n        epochs = list(range(config.EPOCHS))\n        learning_rates = [lrfn(x) for x in epochs]\n        plt.scatter(epochs,learning_rates)\n        plt.show()\n\n    lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=False)\n    return lr_callback\n\nget_lr_callback(plot=True)\n```\n\nI do not know when is the idea for this implementation?\nAnd what is useful to EfficientNet Architecture or in larger? \n\nP/S : I try to find out the answer in comments but maybe it is not exist, please show me if you know.",
    "1744735": "This is simple [ExponentialLR ](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html) with [warmup](https://stackoverflow.com/questions/55933867/what-does-learning-rate-warm-up-mean), it looks like this:\n![lr](https://i.ibb.co/vzkWWwW/image.png)\nIt is not the best and only scheduler for this task, just one of.",
    "1745346": "I would recommend checking out the lr scheduler in fastai, it can give a slightly better performance",
    "1746746": "A lot of the code shared in the public kernels comes from the Google Collab Flowers TPU example, including the LR scheduler.\n\nhttps://colab.research.google.com/notebooks/tpu.ipynb",
    "1746772": "kwentar what is your recommendation?",
    "1746873": "for me works good [CosineAnnealingLR ](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingLR.html) and LR [scheduler](https://fastai1.fast.ai/callbacks.one_cycle.html) from FastAI",
    "1746885": "and that from experience or paper, or any algorithm? @kwentar",
    "1746894": "I mean in this competition from my experience, but fastai says it works everywhere, also [paper ](https://arxiv.org/pdf/1803.09820.pdf) about it"
  },
  "source": "meta"
}