{
  "id": 216278,
  "title": "How to use pre-trained model on kaggle?",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/216278",
  "author_name": "",
  "post_date": "2021-02-02T08:57:07.723473900Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Does anyone know how to use the pre-trained model without turning on the internet on Kaggle?<br>\nI am so confused!<br>\nThanks in advance! </p>",
  "messages": [
    {
      "id": "1182016",
      "postDate": "02/02/2021 08:57:07",
      "content": "<p>Does anyone know how to use the pre-trained model without turning on the internet on Kaggle?<br>\nI am so confused!<br>\nThanks in advance! </p>",
      "rawMarkdown": "Does anyone know how to use the pre-trained model without turning on the internet on Kaggle?\nI am so confused!\nThanks in advance!",
      "votes": null
    },
    {
      "id": "1182083",
      "postDate": "02/02/2021 09:44:23",
      "content": "<p>Hi, you can use an existing dataset or you can create your own dataset with network weights from public networks and attach that dataset to your notebook -&gt; then you can use it without internet.</p>\n<p>A lot of people use EfficientNet this way, or if you want another one, newer or more exotic for example RepVGG, you can use this concrete example (you can use anything, it's just an example):<br>\n<a href=\"https://www.kaggle.com/mobassir/repvgg\" target=\"_blank\">https://www.kaggle.com/mobassir/repvgg</a></p>",
      "rawMarkdown": "Hi, you can use an existing dataset or you can create your own dataset with network weights from public networks and attach that dataset to your notebook -> then you can use it without internet.\n\nA lot of people use EfficientNet this way, or if you want another one, newer or more exotic for example RepVGG, you can use this concrete example (you can use anything, it's just an example):\nhttps://www.kaggle.com/mobassir/repvgg",
      "votes": null
    },
    {
      "id": "1182084",
      "postDate": "02/02/2021 09:44:26",
      "content": "<p>If you are using PyTorch, you can use <code>timm</code> which has a nice collection of pre-trained models</p>\n<p>1, Add the <code>timm</code> repo as a dataset to your notebook; I personally like this one: <a href=\"https://www.kaggle.com/kozodoi/timm-pytorch-image-models\" target=\"_blank\">https://www.kaggle.com/kozodoi/timm-pytorch-image-models</a> (upvote for the dataset owner if you do!)</p>\n<p>2, If you are using efficientnet, you will also need to add the pre-trained weights as a dataset to your notebook too; my choice of dataset is <a href=\"https://www.kaggle.com/ar90ngas/timm-pretrained-efficientnet\" target=\"_blank\">https://www.kaggle.com/ar90ngas/timm-pretrained-efficientnet</a> (similarly, upvote for the dataset owner if you do)</p>\n<p>3, Add the following to your notebook:</p>\n<pre><code>import torch\n\nimport sys\nsys.path.append('../input/timm-pytorch-image-models/pytorch-image-models-master')\nimport timm\n</code></pre>\n<p>4, You can then load the pre-trained weights like so (I'm using efficientnet_b4_ns as an example here):</p>\n<pre><code>arch = 'tf_efficientnet_b4_ns'\npretrained_path = '../input/timm-pretrained-efficientnet/efficientnet/tf_efficientnet_b4_ns-d6313a46.pth'\n\nmodel = timm.create_model(arch, pretrained=False)\nmodel.load_state_dict(torch.load(pretrained_path))\n</code></pre>",
      "rawMarkdown": "If you are using PyTorch, you can use `timm` which has a nice collection of pre-trained models\n\n1, Add the `timm` repo as a dataset to your notebook; I personally like this one: https://www.kaggle.com/kozodoi/timm-pytorch-image-models (upvote for the dataset owner if you do!)\n\n2, If you are using efficientnet, you will also need to add the pre-trained weights as a dataset to your notebook too; my choice of dataset is https://www.kaggle.com/ar90ngas/timm-pretrained-efficientnet (similarly, upvote for the dataset owner if you do)\n\n3, Add the following to your notebook:\n```\nimport torch\n\nimport sys\nsys.path.append('../input/timm-pytorch-image-models/pytorch-image-models-master')\nimport timm\n```\n\n4, You can then load the pre-trained weights like so (I'm using efficientnet_b4_ns as an example here):\n```\narch = 'tf_efficientnet_b4_ns'\npretrained_path = '../input/timm-pretrained-efficientnet/efficientnet/tf_efficientnet_b4_ns-d6313a46.pth'\n\nmodel = timm.create_model(arch, pretrained=False)\nmodel.load_state_dict(torch.load(pretrained_path))\n```",
      "votes": null
    },
    {
      "id": "1182324",
      "postDate": "02/02/2021 12:13:39",
      "content": "<p>Two ways to do it:</p>\n<ul>\n<li>Train and save the model in one notebook with the internet. Load this model in the second notebook and run it on test images without internet and submit this notebook.</li>\n<li>Download and save pre-trained weights yourself in the input directory. <a href=\"https://keras.io/examples/vision/image_classification_efficientnet_fine_tuning/#using-the-latest-efficientnet-weights\" target=\"_blank\">EfficientNet link</a>.</li>\n</ul>",
      "rawMarkdown": "Two ways to do it:\n- Train and save the model in one notebook with the internet. Load this model in the second notebook and run it on test images without internet and submit this notebook.\n- Download and save pre-trained weights yourself in the input directory. [EfficientNet link](https://keras.io/examples/vision/image_classification_efficientnet_fine_tuning/#using-the-latest-efficientnet-weights).",
      "votes": null
    },
    {
      "id": "1182393",
      "postDate": "02/02/2021 12:49:15",
      "content": "<p>You can download weights via Internet. You can find Internet setting to press |&lt; at upper right and go to settings tab. FYI, you can't submit code when you use internet. So you must separate submission code and training code. </p>",
      "rawMarkdown": "You can download weights via Internet. You can find Internet setting to press |< at upper right and go to settings tab. FYI, you can't submit code when you use internet. So you must separate submission code and training code.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1182083,
      "author_name": "killimi",
      "author_url": "",
      "post_date": "02/02/2021 09:44:23",
      "content": "<p>Hi, you can use an existing dataset or you can create your own dataset with network weights from public networks and attach that dataset to your notebook -&gt; then you can use it without internet.</p>\n<p>A lot of people use EfficientNet this way, or if you want another one, newer or more exotic for example RepVGG, you can use this concrete example (you can use anything, it's just an example):<br>\n<a href=\"https://www.kaggle.com/mobassir/repvgg\" target=\"_blank\">https://www.kaggle.com/mobassir/repvgg</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1182084,
      "author_name": "polars",
      "author_url": "",
      "post_date": "02/02/2021 09:44:26",
      "content": "<p>If you are using PyTorch, you can use <code>timm</code> which has a nice collection of pre-trained models</p>\n<p>1, Add the <code>timm</code> repo as a dataset to your notebook; I personally like this one: <a href=\"https://www.kaggle.com/kozodoi/timm-pytorch-image-models\" target=\"_blank\">https://www.kaggle.com/kozodoi/timm-pytorch-image-models</a> (upvote for the dataset owner if you do!)</p>\n<p>2, If you are using efficientnet, you will also need to add the pre-trained weights as a dataset to your notebook too; my choice of dataset is <a href=\"https://www.kaggle.com/ar90ngas/timm-pretrained-efficientnet\" target=\"_blank\">https://www.kaggle.com/ar90ngas/timm-pretrained-efficientnet</a> (similarly, upvote for the dataset owner if you do)</p>\n<p>3, Add the following to your notebook:</p>\n<pre><code>import torch\n\nimport sys\nsys.path.append('../input/timm-pytorch-image-models/pytorch-image-models-master')\nimport timm\n</code></pre>\n<p>4, You can then load the pre-trained weights like so (I'm using efficientnet_b4_ns as an example here):</p>\n<pre><code>arch = 'tf_efficientnet_b4_ns'\npretrained_path = '../input/timm-pretrained-efficientnet/efficientnet/tf_efficientnet_b4_ns-d6313a46.pth'\n\nmodel = timm.create_model(arch, pretrained=False)\nmodel.load_state_dict(torch.load(pretrained_path))\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1182324,
      "author_name": "ravinmechu",
      "author_url": "",
      "post_date": "02/02/2021 12:13:39",
      "content": "<p>Two ways to do it:</p>\n<ul>\n<li>Train and save the model in one notebook with the internet. Load this model in the second notebook and run it on test images without internet and submit this notebook.</li>\n<li>Download and save pre-trained weights yourself in the input directory. <a href=\"https://keras.io/examples/vision/image_classification_efficientnet_fine_tuning/#using-the-latest-efficientnet-weights\" target=\"_blank\">EfficientNet link</a>.</li>\n</ul>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1182393,
      "author_name": "vkehfdl1",
      "author_url": "",
      "post_date": "02/02/2021 12:49:15",
      "content": "<p>You can download weights via Internet. You can find Internet setting to press |&lt; at upper right and go to settings tab. FYI, you can't submit code when you use internet. So you must separate submission code and training code. </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1182016": "Does anyone know how to use the pre-trained model without turning on the internet on Kaggle?\nI am so confused!\nThanks in advance!",
    "1182083": "Hi, you can use an existing dataset or you can create your own dataset with network weights from public networks and attach that dataset to your notebook -> then you can use it without internet.\n\nA lot of people use EfficientNet this way, or if you want another one, newer or more exotic for example RepVGG, you can use this concrete example (you can use anything, it's just an example):\nhttps://www.kaggle.com/mobassir/repvgg",
    "1182084": "If you are using PyTorch, you can use `timm` which has a nice collection of pre-trained models\n\n1, Add the `timm` repo as a dataset to your notebook; I personally like this one: https://www.kaggle.com/kozodoi/timm-pytorch-image-models (upvote for the dataset owner if you do!)\n\n2, If you are using efficientnet, you will also need to add the pre-trained weights as a dataset to your notebook too; my choice of dataset is https://www.kaggle.com/ar90ngas/timm-pretrained-efficientnet (similarly, upvote for the dataset owner if you do)\n\n3, Add the following to your notebook:\n```\nimport torch\n\nimport sys\nsys.path.append('../input/timm-pytorch-image-models/pytorch-image-models-master')\nimport timm\n```\n\n4, You can then load the pre-trained weights like so (I'm using efficientnet_b4_ns as an example here):\n```\narch = 'tf_efficientnet_b4_ns'\npretrained_path = '../input/timm-pretrained-efficientnet/efficientnet/tf_efficientnet_b4_ns-d6313a46.pth'\n\nmodel = timm.create_model(arch, pretrained=False)\nmodel.load_state_dict(torch.load(pretrained_path))\n```",
    "1182324": "Two ways to do it:\n- Train and save the model in one notebook with the internet. Load this model in the second notebook and run it on test images without internet and submit this notebook.\n- Download and save pre-trained weights yourself in the input directory. [EfficientNet link](https://keras.io/examples/vision/image_classification_efficientnet_fine_tuning/#using-the-latest-efficientnet-weights).",
    "1182393": "You can download weights via Internet. You can find Internet setting to press |< at upper right and go to settings tab. FYI, you can't submit code when you use internet. So you must separate submission code and training code."
  },
  "source": "meta"
}