{
  "id": 208415,
  "title": "Can't submit my notebook",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/208415",
  "author_name": "",
  "post_date": "2021-01-03T11:23:51.787451900Z",
  "votes": null,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Hi!</p>\n<p>I can commit and save my notebook, but when I try to submit it to competition i can't click the submit button and I get an error \"Your Notebook cannot use internet access in this competition. Please disable internet in the Notebook editor and save a new version\". I know how to turn off the internet, but my model is based on transfer learning with EfficientNet and turning off the internet prevents the notebook from downloading the necessary model. What can I do to fix this issue?</p>\n<p>Cheers guys. </p>",
  "messages": [
    {
      "id": "1136728",
      "postDate": "01/03/2021 11:23:51",
      "content": "<p>Hi!</p>\n<p>I can commit and save my notebook, but when I try to submit it to competition i can't click the submit button and I get an error \"Your Notebook cannot use internet access in this competition. Please disable internet in the Notebook editor and save a new version\". I know how to turn off the internet, but my model is based on transfer learning with EfficientNet and turning off the internet prevents the notebook from downloading the necessary model. What can I do to fix this issue?</p>\n<p>Cheers guys. </p>",
      "rawMarkdown": "Hi!\n\nI can commit and save my notebook, but when I try to submit it to competition i can't click the submit button and I get an error \"Your Notebook cannot use internet access in this competition. Please disable internet in the Notebook editor and save a new version\". I know how to turn off the internet, but my model is based on transfer learning with EfficientNet and turning off the internet prevents the notebook from downloading the necessary model. What can I do to fix this issue?\n \nCheers guys.",
      "votes": null
    },
    {
      "id": "1136773",
      "postDate": "01/03/2021 12:13:20",
      "content": "<p>What I did is, when I save and commit my notebook, I saved the model.h5.<br>\nThis notebook is added to a new notebook that I used for making predictions and submissions. The newer notebook doesn't need Internet in that way</p>\n<p>I am using Keras, and hence <a href=\"https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model\" target=\"_blank\">load_model()</a></p>",
      "rawMarkdown": "What I did is, when I save and commit my notebook, I saved the model.h5.\nThis notebook is added to a new notebook that I used for making predictions and submissions. The newer notebook doesn't need Internet in that way\n\nI am using Keras, and hence [load_model()](https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model)",
      "votes": null
    },
    {
      "id": "1136953",
      "postDate": "01/03/2021 15:05:54",
      "content": "<p>You need to add the pretrained efficientnet weights file and library as a kaggle dataset and you can use them offline. The alternative and easiest way is to have separate notebooks for training and inference, where you save the trained model weights as a dataset and use them in your inference notebook without internet.</p>",
      "rawMarkdown": "You need to add the pretrained efficientnet weights file and library as a kaggle dataset and you can use them offline. The alternative and easiest way is to have separate notebooks for training and inference, where you save the trained model weights as a dataset and use them in your inference notebook without internet.",
      "votes": null
    },
    {
      "id": "1138297",
      "postDate": "01/04/2021 14:58:58",
      "content": "<p>Thanks, your method worked for me</p>",
      "rawMarkdown": "Thanks, your method worked for me",
      "votes": null
    },
    {
      "id": "1138344",
      "postDate": "01/04/2021 16:02:26",
      "content": "<p>you're welcome. the alternative method <a href=\"https://www.kaggle.com/yovinyahathugoda\" target=\"_blank\">@yovinyahathugoda</a> mentioned is the same as what I said.</p>",
      "rawMarkdown": "you're welcome. the alternative method @yovinyahathugoda mentioned is the same as what I said.",
      "votes": null
    },
    {
      "id": "1138597",
      "postDate": "01/04/2021 19:48:55",
      "content": "<p>Hello <a href=\"https://www.kaggle.com/tymonhuchla\" target=\"_blank\">@tymonhuchla</a> ,<br>\nHere is my approach:</p>\n<h6>step n.1</h6>\n<p>In your notebook load into your input by using <code>+ Add data</code> button  this library: <a href=\"url\" target=\"_blank\">https://www.kaggle.com/filchy/pytorch-img-class-models</a></p>\n<h6>step n.2</h6>\n<p>Write this code to enable his importing and then import it.</p>\n<pre><code>import sys\npackage_path = \"../input/pytorch-img-class-models/pytorch-image-models-master\"\nsys.path.append(package_path)\n\nimport timm\n</code></pre>\n<h6>step n.3</h6>\n<p>Create and <strong>train</strong> your model in training notebook. For training you will probably want to use pretrained weights for better accuracy, so you need to enable internet. After training you need to save those weights.<br>\nmodel:</p>\n<pre><code>class CustomEffNet(nn.Module):\n    def __init__(self, model_name:str=\"tf_efficientnet_b3\", pretrained:bool=True, n_out:int=5):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n\n        n_features = self.model.classifier.in_features\n        self.model.classifier = nn.Linear(n_features, n_out)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\nmodel = CustomEffNet(\"tf_efficientnet_b3\", True, 5)\n</code></pre>\n<h6>step n.4</h6>\n<p>For making submission you will create same model and change variable <code>pretrained = False</code> in your inference notebook. Then you will load your pretrained weights from train notebook (step n.3) and then you can run notebook without using internet.<br>\nmodel:</p>\n<pre><code>model = CustomEffNet(\"tf_efficientnet_b3\", False, 5)\nmodel.load_state_dict(torch.load(WEIGHTS_PATH))\n</code></pre>\n<hr>\n<p>By this approach you will need internet just for your training part (training notebook), but for your submission (inference notebook) you can disable internet.<br>\nHope it will help you. If not, and there are any questions, just type here and we can make solution 👍</p>",
      "rawMarkdown": "Hello @tymonhuchla ,\nHere is my approach:\n###### step n.1\nIn your notebook load into your input by using ```+ Add data``` button  this library: [https://www.kaggle.com/filchy/pytorch-img-class-models](url)\n###### step n.2\nWrite this code to enable his importing and then import it.\n```\nimport sys\npackage_path = \"../input/pytorch-img-class-models/pytorch-image-models-master\"\nsys.path.append(package_path)\n\nimport timm\n```\n###### step n.3\nCreate and **train** your model in training notebook. For training you will probably want to use pretrained weights for better accuracy, so you need to enable internet. After training you need to save those weights.\nmodel:\n```\nclass CustomEffNet(nn.Module):\n    def __init__(self, model_name:str=\"tf_efficientnet_b3\", pretrained:bool=True, n_out:int=5):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n\n        n_features = self.model.classifier.in_features\n        self.model.classifier = nn.Linear(n_features, n_out)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\nmodel = CustomEffNet(\"tf_efficientnet_b3\", True, 5)\n```\n###### step n.4\nFor making submission you will create same model and change variable ```pretrained = False``` in your inference notebook. Then you will load your pretrained weights from train notebook (step n.3) and then you can run notebook without using internet.\nmodel:\n```\nmodel = CustomEffNet(\"tf_efficientnet_b3\", False, 5)\nmodel.load_state_dict(torch.load(WEIGHTS_PATH))\n```\n___\nBy this approach you will need internet just for your training part (training notebook), but for your submission (inference notebook) you can disable internet.\nHope it will help you. If not, and there are any questions, just type here and we can make solution 👍",
      "votes": null
    },
    {
      "id": "1139679",
      "postDate": "01/05/2021 14:59:50",
      "content": "<p><a href=\"https://www.kaggle.com/filchy\" target=\"_blank\">@filchy</a> Thanks for your method.I use the same way as you mentioned,but when I load the weights it gets some error.Can you help me with that?Thanks</p>\n<hr>\n<p>ModuleAttributeError                      Traceback (most recent call last)<br>\n in <br>\n     14         patience = es_patience  # Current patience counter<br>\n     15 #         model = torch.load(model_path)  # Loading best model of this fold<br>\n---&gt; 16         model.load_state_dict(torch.load(model_path))<br>\n     17         model = model.to(device)<br>\n     18         model.eval()  # switch model to the evaluation mode</p>\n<p>/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)<br>\n   1023         # copy state_dict so _load_from_state_dict can modify it<br>\n   1024         metadata = getattr(state_dict, '_metadata', None)<br>\n-&gt; 1025         state_dict = state_dict.copy()<br>\n   1026         if metadata is not None:<br>\n   1027             state_dict._metadata = metadata</p>\n<p>/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in <strong>getattr</strong>(self, name)<br>\n    777                 return modules[name]<br>\n    778         raise ModuleAttributeError(\"'{}' object has no attribute '{}'\".format(<br>\n--&gt; 779             type(self).<strong>name</strong>, name))<br>\n    780 <br>\n    781     def <strong>setattr</strong>(self, name: str, value: Union[Tensor, 'Module']) -&gt; None:</p>\n<p>ModuleAttributeError: 'CustomEffNet' object has no attribute 'copy'</p>",
      "rawMarkdown": "filchy Thanks for your method.I use the same way as you mentioned,but when I load the weights it gets some error.Can you help me with that?Thanks\n\n\n---------------------------------------------------------------------------\nModuleAttributeError                      Traceback (most recent call last)\n<ipython-input-21-6900ac8473d6> in <module>\n     14         patience = es_patience  # Current patience counter\n     15 #         model = torch.load(model_path)  # Loading best model of this fold\n---> 16         model.load_state_dict(torch.load(model_path))\n     17         model = model.to(device)\n     18         model.eval()  # switch model to the evaluation mode\n\n/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)\n   1023         # copy state_dict so _load_from_state_dict can modify it\n   1024         metadata = getattr(state_dict, '_metadata', None)\n-> 1025         state_dict = state_dict.copy()\n   1026         if metadata is not None:\n   1027             state_dict._metadata = metadata\n\n/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)\n    777                 return modules[name]\n    778         raise ModuleAttributeError(\"'{}' object has no attribute '{}'\".format(\n--> 779             type(self).__name__, name))\n    780 \n    781     def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:\n\nModuleAttributeError: 'CustomEffNet' object has no attribute 'copy'",
      "votes": null
    },
    {
      "id": "1140110",
      "postDate": "01/05/2021 20:09:32",
      "content": "<p>Hello <a href=\"https://www.kaggle.com/carlwuuu\" target=\"_blank\">@carlwuuu</a>,<br>\nIt seems that  this error is occured by saving your whole model instead of saving just model weights. I suppose that you saved your model like this:<br>\n<code>torch.save(model, \"best_model.pt\")</code><br>\nInstead of this. <strong>(This is correct)</strong>:</p>\n<pre><code>torch.save(model.state_dict(), \"best_model.pt\")\n</code></pre>\n<hr>\n<h5>Solution:</h5>\n<p>If I am right and this is where you made mistake than you have more variants how to load your pretrained model weights correctly.</p>\n<h6># 1st variant</h6>\n<p>If you saved your full model and not just weights. By using torch.load function you should load your model with your weights successfully:</p>\n<pre><code>model = torch.load(MODEL_PATH)\n</code></pre>\n<h6># 2nd variant</h6>\n<p>Load your model pretrained weights into your new model.</p>\n<pre><code>model.load_state_dict(torch.load(MODEL_PATH).state_dict())\n</code></pre>\n<h6># 3rd variant</h6>\n<p>You can train your model again and than save it right.</p>\n<pre><code>torch.save(model.state_dict(), \"best_model.pt\")\n</code></pre>\n<hr>\n<p>Let us know here about the result please 👍</p>",
      "rawMarkdown": "Hello @carlwuuu,\nIt seems that  this error is occured by saving your whole model instead of saving just model weights. I suppose that you saved your model like this:\n```torch.save(model, \"best_model.pt\")```\nInstead of this. **(This is correct)**:\n```\ntorch.save(model.state_dict(), \"best_model.pt\")\n```\n___\n##### Solution:\nIf I am right and this is where you made mistake than you have more variants how to load your pretrained model weights correctly.\n####### 1st variant\nIf you saved your full model and not just weights. By using torch.load function you should load your model with your weights successfully:\n```\nmodel = torch.load(MODEL_PATH)\n```\n####### 2nd variant\nLoad your model pretrained weights into your new model.\n```\nmodel.load_state_dict(torch.load(MODEL_PATH).state_dict())\n```\n####### 3rd variant\nYou can train your model again and than save it right.\n```\ntorch.save(model.state_dict(), \"best_model.pt\")\n```\n___\nLet us know here about the result please 👍",
      "votes": null
    },
    {
      "id": "1142077",
      "postDate": "01/07/2021 06:07:38",
      "content": "<p>Hello <a href=\"https://www.kaggle.com/filchy\" target=\"_blank\">@filchy</a> ,Thanks for your solution.you are correct that I use **torch.save(model, \"best_model.pth\") ** saved my model,but I found that it is not root cause.I trained the model with <strong>efficientnet_pytorch.Efficientnet.from_pretrained(\"efficientnet-bX\")</strong>,however in another notebook I test the model like you suggested,so it goes wrong.I changed training notebook as step n.3,it's ok now.Thank you</p>",
      "rawMarkdown": "Hello @filchy ,Thanks for your solution.you are correct that I use **torch.save(model, \"best_model.pth\") ** saved my model,but I found that it is not root cause.I trained the model with **efficientnet_pytorch.Efficientnet.from_pretrained(\"efficientnet-bX\")**,however in another notebook I test the model like you suggested,so it goes wrong.I changed training notebook as step n.3,it's ok now.Thank you",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1136773,
      "author_name": "mohitve",
      "author_url": "",
      "post_date": "01/03/2021 12:13:20",
      "content": "<p>What I did is, when I save and commit my notebook, I saved the model.h5.<br>\nThis notebook is added to a new notebook that I used for making predictions and submissions. The newer notebook doesn't need Internet in that way</p>\n<p>I am using Keras, and hence <a href=\"https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model\" target=\"_blank\">load_model()</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1138297,
          "author_name": "tymonhuchla",
          "author_url": "",
          "post_date": "01/04/2021 14:58:58",
          "content": "<p>Thanks, your method worked for me</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1138344,
          "author_name": "mohitve",
          "author_url": "",
          "post_date": "01/04/2021 16:02:26",
          "content": "<p>you're welcome. the alternative method <a href=\"https://www.kaggle.com/yovinyahathugoda\" target=\"_blank\">@yovinyahathugoda</a> mentioned is the same as what I said.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1136953,
      "author_name": "yovinyahathugoda",
      "author_url": "",
      "post_date": "01/03/2021 15:05:54",
      "content": "<p>You need to add the pretrained efficientnet weights file and library as a kaggle dataset and you can use them offline. The alternative and easiest way is to have separate notebooks for training and inference, where you save the trained model weights as a dataset and use them in your inference notebook without internet.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1138597,
      "author_name": "filchy",
      "author_url": "",
      "post_date": "01/04/2021 19:48:55",
      "content": "<p>Hello <a href=\"https://www.kaggle.com/tymonhuchla\" target=\"_blank\">@tymonhuchla</a> ,<br>\nHere is my approach:</p>\n<h6>step n.1</h6>\n<p>In your notebook load into your input by using <code>+ Add data</code> button  this library: <a href=\"url\" target=\"_blank\">https://www.kaggle.com/filchy/pytorch-img-class-models</a></p>\n<h6>step n.2</h6>\n<p>Write this code to enable his importing and then import it.</p>\n<pre><code>import sys\npackage_path = \"../input/pytorch-img-class-models/pytorch-image-models-master\"\nsys.path.append(package_path)\n\nimport timm\n</code></pre>\n<h6>step n.3</h6>\n<p>Create and <strong>train</strong> your model in training notebook. For training you will probably want to use pretrained weights for better accuracy, so you need to enable internet. After training you need to save those weights.<br>\nmodel:</p>\n<pre><code>class CustomEffNet(nn.Module):\n    def __init__(self, model_name:str=\"tf_efficientnet_b3\", pretrained:bool=True, n_out:int=5):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n\n        n_features = self.model.classifier.in_features\n        self.model.classifier = nn.Linear(n_features, n_out)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\nmodel = CustomEffNet(\"tf_efficientnet_b3\", True, 5)\n</code></pre>\n<h6>step n.4</h6>\n<p>For making submission you will create same model and change variable <code>pretrained = False</code> in your inference notebook. Then you will load your pretrained weights from train notebook (step n.3) and then you can run notebook without using internet.<br>\nmodel:</p>\n<pre><code>model = CustomEffNet(\"tf_efficientnet_b3\", False, 5)\nmodel.load_state_dict(torch.load(WEIGHTS_PATH))\n</code></pre>\n<hr>\n<p>By this approach you will need internet just for your training part (training notebook), but for your submission (inference notebook) you can disable internet.<br>\nHope it will help you. If not, and there are any questions, just type here and we can make solution 👍</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1139679,
      "author_name": "carlwuuu",
      "author_url": "",
      "post_date": "01/05/2021 14:59:50",
      "content": "<p><a href=\"https://www.kaggle.com/filchy\" target=\"_blank\">@filchy</a> Thanks for your method.I use the same way as you mentioned,but when I load the weights it gets some error.Can you help me with that?Thanks</p>\n<hr>\n<p>ModuleAttributeError                      Traceback (most recent call last)<br>\n in <br>\n     14         patience = es_patience  # Current patience counter<br>\n     15 #         model = torch.load(model_path)  # Loading best model of this fold<br>\n---&gt; 16         model.load_state_dict(torch.load(model_path))<br>\n     17         model = model.to(device)<br>\n     18         model.eval()  # switch model to the evaluation mode</p>\n<p>/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)<br>\n   1023         # copy state_dict so _load_from_state_dict can modify it<br>\n   1024         metadata = getattr(state_dict, '_metadata', None)<br>\n-&gt; 1025         state_dict = state_dict.copy()<br>\n   1026         if metadata is not None:<br>\n   1027             state_dict._metadata = metadata</p>\n<p>/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in <strong>getattr</strong>(self, name)<br>\n    777                 return modules[name]<br>\n    778         raise ModuleAttributeError(\"'{}' object has no attribute '{}'\".format(<br>\n--&gt; 779             type(self).<strong>name</strong>, name))<br>\n    780 <br>\n    781     def <strong>setattr</strong>(self, name: str, value: Union[Tensor, 'Module']) -&gt; None:</p>\n<p>ModuleAttributeError: 'CustomEffNet' object has no attribute 'copy'</p>",
      "votes": null,
      "replies": [
        {
          "id": 1140110,
          "author_name": "filchy",
          "author_url": "",
          "post_date": "01/05/2021 20:09:32",
          "content": "<p>Hello <a href=\"https://www.kaggle.com/carlwuuu\" target=\"_blank\">@carlwuuu</a>,<br>\nIt seems that  this error is occured by saving your whole model instead of saving just model weights. I suppose that you saved your model like this:<br>\n<code>torch.save(model, \"best_model.pt\")</code><br>\nInstead of this. <strong>(This is correct)</strong>:</p>\n<pre><code>torch.save(model.state_dict(), \"best_model.pt\")\n</code></pre>\n<hr>\n<h5>Solution:</h5>\n<p>If I am right and this is where you made mistake than you have more variants how to load your pretrained model weights correctly.</p>\n<h6># 1st variant</h6>\n<p>If you saved your full model and not just weights. By using torch.load function you should load your model with your weights successfully:</p>\n<pre><code>model = torch.load(MODEL_PATH)\n</code></pre>\n<h6># 2nd variant</h6>\n<p>Load your model pretrained weights into your new model.</p>\n<pre><code>model.load_state_dict(torch.load(MODEL_PATH).state_dict())\n</code></pre>\n<h6># 3rd variant</h6>\n<p>You can train your model again and than save it right.</p>\n<pre><code>torch.save(model.state_dict(), \"best_model.pt\")\n</code></pre>\n<hr>\n<p>Let us know here about the result please 👍</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1142077,
      "author_name": "carlwuuu",
      "author_url": "",
      "post_date": "01/07/2021 06:07:38",
      "content": "<p>Hello <a href=\"https://www.kaggle.com/filchy\" target=\"_blank\">@filchy</a> ,Thanks for your solution.you are correct that I use **torch.save(model, \"best_model.pth\") ** saved my model,but I found that it is not root cause.I trained the model with <strong>efficientnet_pytorch.Efficientnet.from_pretrained(\"efficientnet-bX\")</strong>,however in another notebook I test the model like you suggested,so it goes wrong.I changed training notebook as step n.3,it's ok now.Thank you</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1136728": "Hi!\n\nI can commit and save my notebook, but when I try to submit it to competition i can't click the submit button and I get an error \"Your Notebook cannot use internet access in this competition. Please disable internet in the Notebook editor and save a new version\". I know how to turn off the internet, but my model is based on transfer learning with EfficientNet and turning off the internet prevents the notebook from downloading the necessary model. What can I do to fix this issue?\n \nCheers guys.",
    "1136773": "What I did is, when I save and commit my notebook, I saved the model.h5.\nThis notebook is added to a new notebook that I used for making predictions and submissions. The newer notebook doesn't need Internet in that way\n\nI am using Keras, and hence [load_model()](https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model)",
    "1136953": "You need to add the pretrained efficientnet weights file and library as a kaggle dataset and you can use them offline. The alternative and easiest way is to have separate notebooks for training and inference, where you save the trained model weights as a dataset and use them in your inference notebook without internet.",
    "1138297": "Thanks, your method worked for me",
    "1138344": "you're welcome. the alternative method @yovinyahathugoda mentioned is the same as what I said.",
    "1138597": "Hello @tymonhuchla ,\nHere is my approach:\n###### step n.1\nIn your notebook load into your input by using ```+ Add data``` button  this library: [https://www.kaggle.com/filchy/pytorch-img-class-models](url)\n###### step n.2\nWrite this code to enable his importing and then import it.\n```\nimport sys\npackage_path = \"../input/pytorch-img-class-models/pytorch-image-models-master\"\nsys.path.append(package_path)\n\nimport timm\n```\n###### step n.3\nCreate and **train** your model in training notebook. For training you will probably want to use pretrained weights for better accuracy, so you need to enable internet. After training you need to save those weights.\nmodel:\n```\nclass CustomEffNet(nn.Module):\n    def __init__(self, model_name:str=\"tf_efficientnet_b3\", pretrained:bool=True, n_out:int=5):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n\n        n_features = self.model.classifier.in_features\n        self.model.classifier = nn.Linear(n_features, n_out)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\nmodel = CustomEffNet(\"tf_efficientnet_b3\", True, 5)\n```\n###### step n.4\nFor making submission you will create same model and change variable ```pretrained = False``` in your inference notebook. Then you will load your pretrained weights from train notebook (step n.3) and then you can run notebook without using internet.\nmodel:\n```\nmodel = CustomEffNet(\"tf_efficientnet_b3\", False, 5)\nmodel.load_state_dict(torch.load(WEIGHTS_PATH))\n```\n___\nBy this approach you will need internet just for your training part (training notebook), but for your submission (inference notebook) you can disable internet.\nHope it will help you. If not, and there are any questions, just type here and we can make solution 👍",
    "1139679": "filchy Thanks for your method.I use the same way as you mentioned,but when I load the weights it gets some error.Can you help me with that?Thanks\n\n\n---------------------------------------------------------------------------\nModuleAttributeError                      Traceback (most recent call last)\n<ipython-input-21-6900ac8473d6> in <module>\n     14         patience = es_patience  # Current patience counter\n     15 #         model = torch.load(model_path)  # Loading best model of this fold\n---> 16         model.load_state_dict(torch.load(model_path))\n     17         model = model.to(device)\n     18         model.eval()  # switch model to the evaluation mode\n\n/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)\n   1023         # copy state_dict so _load_from_state_dict can modify it\n   1024         metadata = getattr(state_dict, '_metadata', None)\n-> 1025         state_dict = state_dict.copy()\n   1026         if metadata is not None:\n   1027             state_dict._metadata = metadata\n\n/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)\n    777                 return modules[name]\n    778         raise ModuleAttributeError(\"'{}' object has no attribute '{}'\".format(\n--> 779             type(self).__name__, name))\n    780 \n    781     def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:\n\nModuleAttributeError: 'CustomEffNet' object has no attribute 'copy'",
    "1140110": "Hello @carlwuuu,\nIt seems that  this error is occured by saving your whole model instead of saving just model weights. I suppose that you saved your model like this:\n```torch.save(model, \"best_model.pt\")```\nInstead of this. **(This is correct)**:\n```\ntorch.save(model.state_dict(), \"best_model.pt\")\n```\n___\n##### Solution:\nIf I am right and this is where you made mistake than you have more variants how to load your pretrained model weights correctly.\n####### 1st variant\nIf you saved your full model and not just weights. By using torch.load function you should load your model with your weights successfully:\n```\nmodel = torch.load(MODEL_PATH)\n```\n####### 2nd variant\nLoad your model pretrained weights into your new model.\n```\nmodel.load_state_dict(torch.load(MODEL_PATH).state_dict())\n```\n####### 3rd variant\nYou can train your model again and than save it right.\n```\ntorch.save(model.state_dict(), \"best_model.pt\")\n```\n___\nLet us know here about the result please 👍",
    "1142077": "Hello @filchy ,Thanks for your solution.you are correct that I use **torch.save(model, \"best_model.pth\") ** saved my model,but I found that it is not root cause.I trained the model with **efficientnet_pytorch.Efficientnet.from_pretrained(\"efficientnet-bX\")**,however in another notebook I test the model like you suggested,so it goes wrong.I changed training notebook as step n.3,it's ok now.Thank you"
  },
  "source": "meta"
}