{
  "id": 200308,
  "title": "Newbie Questions using Pretrained model with Internet Off?",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/200308",
  "author_name": "",
  "post_date": "2020-11-29T22:40:17.399985500Z",
  "votes": 4,
  "comment_count": 8,
  "views": 0,
  "content": "<p>I created model using EfficientNetB2,  It worked fine.  However when I turn off the Internet and try to run it for submission,  it fails to download the model.  </p>\n<p>How do you guys setup the notebook to use pretrained models without Internet?</p>\n<p>Thanks advance.</p>\n<p>Lu</p>",
  "messages": [
    {
      "id": "1095746",
      "postDate": "11/29/2020 22:40:17",
      "content": "<p>I created model using EfficientNetB2,  It worked fine.  However when I turn off the Internet and try to run it for submission,  it fails to download the model.  </p>\n<p>How do you guys setup the notebook to use pretrained models without Internet?</p>\n<p>Thanks advance.</p>\n<p>Lu</p>",
      "rawMarkdown": "I created model using EfficientNetB2,  It worked fine.  However when I turn off the Internet and try to run it for submission,  it fails to download the model.  \n\nHow do you guys setup the notebook to use pretrained models without Internet?\n\nThanks advance.\n\nLu",
      "votes": null
    },
    {
      "id": "1095777",
      "postDate": "11/30/2020 00:09:29",
      "content": "<p><a href=\"https://www.kaggle.com/luqing2\" target=\"_blank\">@luqing2</a></p>\n<ol>\n<li>Save weights of your model (or model with weights) in notebook with <code>model.save('saved_model.h5')</code>.</li>\n<li>Click <code>Save Version</code> in top right corner on your notebook page.</li>\n<li>Click <code>Advanced settings</code>, then select <code>Always save output</code>, then click <code>Save</code>.</li>\n<li>Choose <code>Quick save</code> option in dropdown and click <code>Save</code>.</li>\n<li>In left bottom corner you will see a modal with saving info. After successful save just click <code>View</code> button in this modal. (If you miss modal, remove <code>/edit/bla/bla/bla</code> in notebook url).<br>\n5.5. (You should go to notebook view mode)</li>\n<li>Find your weights/save model in output section</li>\n<li>Click <code>+ New Dataset</code>.</li>\n<li>Create another notebook (only for submission).</li>\n<li>Go to freshly created notebook.</li>\n<li>Click <code>Add data</code> button in top right corner in your notebook, select <code>Your datasets</code> chips in first tab of model (I mean <code>Datasets</code> tab), and then click <code>Add</code>. Then you will see your dataset directory in <code>input</code> folder.</li>\n<li>Write code for inference, your model/weights can be imported from <code>input</code> folder.</li>\n</ol>\n<p>Good luck 💪</p>",
      "rawMarkdown": "luqing2\n\n1. Save weights of your model (or model with weights) in notebook with `model.save('saved_model.h5')`.\n2. Click `Save Version` in top right corner on your notebook page.\n3. Click `Advanced settings`, then select `Always save output`, then click `Save`.\n4. Choose `Quick save` option in dropdown and click `Save`.\n5. In left bottom corner you will see a modal with saving info. After successful save just click `View` button in this modal. (If you miss modal, remove `/edit/bla/bla/bla` in notebook url).\n5.5. (You should go to notebook view mode)\n6. Find your weights/save model in output section\n7. Click `+ New Dataset`.\n8. Create another notebook (only for submission).\n9. Go to freshly created notebook.\n10. Click `Add data` button in top right corner in your notebook, select `Your datasets` chips in first tab of model (I mean `Datasets` tab), and then click `Add`. Then you will see your dataset directory in `input` folder.\n11. Write code for inference, your model/weights can be imported from `input` folder.\n\nGood luck 💪",
      "votes": null
    },
    {
      "id": "1095780",
      "postDate": "11/30/2020 00:16:12",
      "content": "<p>I found I had to rebuild the EfficientNet model to get things to work with Tensorflow/Keras.</p>\n<p>Also had to use an older Kaggle Docker. Not sure what version of something is incompatible.</p>\n<p>Sample notebook that loads EfficientNet without Internet and loads saved model and weights:</p>\n<p><a href=\"https://www.kaggle.com/richardepstein/efficientnet-commit-inference-old-docker\" target=\"_blank\">https://www.kaggle.com/richardepstein/efficientnet-commit-inference-old-docker</a></p>\n<p>-Rich</p>",
      "rawMarkdown": "I found I had to rebuild the EfficientNet model to get things to work with Tensorflow/Keras.\n\nAlso had to use an older Kaggle Docker. Not sure what version of something is incompatible.\n\nSample notebook that loads EfficientNet without Internet and loads saved model and weights:\n\nhttps://www.kaggle.com/richardepstein/efficientnet-commit-inference-old-docker\n\n-Rich",
      "votes": null
    },
    {
      "id": "1095845",
      "postDate": "11/30/2020 02:17:02",
      "content": "<p>Thank you a bunch Oleg for your detailed instruction.  I will try the steps you suggested. </p>",
      "rawMarkdown": "Thank you a bunch Oleg for your detailed instruction.  I will try the steps you suggested.",
      "votes": null
    },
    {
      "id": "1095846",
      "postDate": "11/30/2020 02:17:32",
      "content": "<p>Thank you much for the response.</p>",
      "rawMarkdown": "Thank you much for the response.",
      "votes": null
    },
    {
      "id": "1096865",
      "postDate": "11/30/2020 20:42:13",
      "content": "<p>Thanks,  I got the idea.  So you don't have to make another new notebook.  You can import the dataset to the notebook where you exported the output as dataset.  That is nice.  Thanks.</p>",
      "rawMarkdown": "Thanks,  I got the idea.  So you don't have to make another new notebook.  You can import the dataset to the notebook where you exported the output as dataset.  That is nice.  Thanks.",
      "votes": null
    },
    {
      "id": "1099020",
      "postDate": "12/02/2020 02:57:54",
      "content": "<p>Let me know if you still have problems, I can guide you if you are using PyTorch.</p>",
      "rawMarkdown": "Let me know if you still have problems, I can guide you if you are using PyTorch.",
      "votes": null
    },
    {
      "id": "1099704",
      "postDate": "12/02/2020 14:49:37",
      "content": "<p>Thanks for the offer,  it works now.</p>",
      "rawMarkdown": "Thanks for the offer,  it works now.",
      "votes": null
    },
    {
      "id": "2963293",
      "postDate": "08/18/2024 15:02:25",
      "content": "<p>thanks !! But I had to face some problems since I was creating my custom model using VGG16… So I would say after following your 1st 10 steps follow mine---</p>\n<ol>\n<li>Ensure that you Must export the model in this way .. </li>\n</ol>\n<blockquote>\n  <p>torch.save(model, 'my_VGG16_full_model.pth')</p>\n</blockquote>\n<p>This wil save weights with architecture<br>\n​2. Then create a new notebook and copy paste your custom Model 1st .</p>\n<ol>\n<li>Then write this command to import trained model weights and layers</li>\n</ol>\n<blockquote>\n  <p>import model = torch.load(path)</p>\n</blockquote>\n<p>and you are ready to go!! Now <code>model.eval()</code></p>",
      "rawMarkdown": "thanks !! But I had to face some problems since I was creating my custom model using VGG16... So I would say after following your 1st 10 steps follow mine---\n1. Ensure that you Must export the model in this way .. \n\n>torch.save(model, 'my_VGG16_full_model.pth')\n\nThis wil save weights with architecture\n​2. Then create a new notebook and copy paste your custom Model 1st .\n3. Then write this command to import trained model weights and layers\n>import model = torch.load(path)\n\nand you are ready to go!! Now `model.eval()`",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1095777,
      "author_name": "khlevnov",
      "author_url": "",
      "post_date": "11/30/2020 00:09:29",
      "content": "<p><a href=\"https://www.kaggle.com/luqing2\" target=\"_blank\">@luqing2</a></p>\n<ol>\n<li>Save weights of your model (or model with weights) in notebook with <code>model.save('saved_model.h5')</code>.</li>\n<li>Click <code>Save Version</code> in top right corner on your notebook page.</li>\n<li>Click <code>Advanced settings</code>, then select <code>Always save output</code>, then click <code>Save</code>.</li>\n<li>Choose <code>Quick save</code> option in dropdown and click <code>Save</code>.</li>\n<li>In left bottom corner you will see a modal with saving info. After successful save just click <code>View</code> button in this modal. (If you miss modal, remove <code>/edit/bla/bla/bla</code> in notebook url).<br>\n5.5. (You should go to notebook view mode)</li>\n<li>Find your weights/save model in output section</li>\n<li>Click <code>+ New Dataset</code>.</li>\n<li>Create another notebook (only for submission).</li>\n<li>Go to freshly created notebook.</li>\n<li>Click <code>Add data</code> button in top right corner in your notebook, select <code>Your datasets</code> chips in first tab of model (I mean <code>Datasets</code> tab), and then click <code>Add</code>. Then you will see your dataset directory in <code>input</code> folder.</li>\n<li>Write code for inference, your model/weights can be imported from <code>input</code> folder.</li>\n</ol>\n<p>Good luck 💪</p>",
      "votes": null,
      "replies": [
        {
          "id": 1095845,
          "author_name": "luqing2",
          "author_url": "",
          "post_date": "11/30/2020 02:17:02",
          "content": "<p>Thank you a bunch Oleg for your detailed instruction.  I will try the steps you suggested. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 2963293,
          "author_name": "dipit099",
          "author_url": "",
          "post_date": "08/18/2024 15:02:25",
          "content": "<p>thanks !! But I had to face some problems since I was creating my custom model using VGG16… So I would say after following your 1st 10 steps follow mine---</p>\n<ol>\n<li>Ensure that you Must export the model in this way .. </li>\n</ol>\n<blockquote>\n  <p>torch.save(model, 'my_VGG16_full_model.pth')</p>\n</blockquote>\n<p>This wil save weights with architecture<br>\n​2. Then create a new notebook and copy paste your custom Model 1st .</p>\n<ol>\n<li>Then write this command to import trained model weights and layers</li>\n</ol>\n<blockquote>\n  <p>import model = torch.load(path)</p>\n</blockquote>\n<p>and you are ready to go!! Now <code>model.eval()</code></p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1095780,
      "author_name": "richardepstein",
      "author_url": "",
      "post_date": "11/30/2020 00:16:12",
      "content": "<p>I found I had to rebuild the EfficientNet model to get things to work with Tensorflow/Keras.</p>\n<p>Also had to use an older Kaggle Docker. Not sure what version of something is incompatible.</p>\n<p>Sample notebook that loads EfficientNet without Internet and loads saved model and weights:</p>\n<p><a href=\"https://www.kaggle.com/richardepstein/efficientnet-commit-inference-old-docker\" target=\"_blank\">https://www.kaggle.com/richardepstein/efficientnet-commit-inference-old-docker</a></p>\n<p>-Rich</p>",
      "votes": null,
      "replies": [
        {
          "id": 1095846,
          "author_name": "luqing2",
          "author_url": "",
          "post_date": "11/30/2020 02:17:32",
          "content": "<p>Thank you much for the response.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1099020,
      "author_name": "reighns",
      "author_url": "",
      "post_date": "12/02/2020 02:57:54",
      "content": "<p>Let me know if you still have problems, I can guide you if you are using PyTorch.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1099704,
          "author_name": "luqing2",
          "author_url": "",
          "post_date": "12/02/2020 14:49:37",
          "content": "<p>Thanks for the offer,  it works now.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1096865,
      "author_name": "luqing2",
      "author_url": "",
      "post_date": "11/30/2020 20:42:13",
      "content": "<p>Thanks,  I got the idea.  So you don't have to make another new notebook.  You can import the dataset to the notebook where you exported the output as dataset.  That is nice.  Thanks.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1095746": "I created model using EfficientNetB2,  It worked fine.  However when I turn off the Internet and try to run it for submission,  it fails to download the model.  \n\nHow do you guys setup the notebook to use pretrained models without Internet?\n\nThanks advance.\n\nLu",
    "1095777": "luqing2\n\n1. Save weights of your model (or model with weights) in notebook with `model.save('saved_model.h5')`.\n2. Click `Save Version` in top right corner on your notebook page.\n3. Click `Advanced settings`, then select `Always save output`, then click `Save`.\n4. Choose `Quick save` option in dropdown and click `Save`.\n5. In left bottom corner you will see a modal with saving info. After successful save just click `View` button in this modal. (If you miss modal, remove `/edit/bla/bla/bla` in notebook url).\n5.5. (You should go to notebook view mode)\n6. Find your weights/save model in output section\n7. Click `+ New Dataset`.\n8. Create another notebook (only for submission).\n9. Go to freshly created notebook.\n10. Click `Add data` button in top right corner in your notebook, select `Your datasets` chips in first tab of model (I mean `Datasets` tab), and then click `Add`. Then you will see your dataset directory in `input` folder.\n11. Write code for inference, your model/weights can be imported from `input` folder.\n\nGood luck 💪",
    "1095780": "I found I had to rebuild the EfficientNet model to get things to work with Tensorflow/Keras.\n\nAlso had to use an older Kaggle Docker. Not sure what version of something is incompatible.\n\nSample notebook that loads EfficientNet without Internet and loads saved model and weights:\n\nhttps://www.kaggle.com/richardepstein/efficientnet-commit-inference-old-docker\n\n-Rich",
    "1095845": "Thank you a bunch Oleg for your detailed instruction.  I will try the steps you suggested.",
    "1095846": "Thank you much for the response.",
    "1096865": "Thanks,  I got the idea.  So you don't have to make another new notebook.  You can import the dataset to the notebook where you exported the output as dataset.  That is nice.  Thanks.",
    "1099020": "Let me know if you still have problems, I can guide you if you are using PyTorch.",
    "1099704": "Thanks for the offer,  it works now.",
    "2963293": "thanks !! But I had to face some problems since I was creating my custom model using VGG16... So I would say after following your 1st 10 steps follow mine---\n1. Ensure that you Must export the model in this way .. \n\n>torch.save(model, 'my_VGG16_full_model.pth')\n\nThis wil save weights with architecture\n​2. Then create a new notebook and copy paste your custom Model 1st .\n3. Then write this command to import trained model weights and layers\n>import model = torch.load(path)\n\nand you are ready to go!! Now `model.eval()`"
  },
  "source": "meta"
}