{
  "id": 153194,
  "title": "How to load model without Internet access?",
  "url": "/competitions/global-wheat-detection/discussion/153194",
  "author_name": "",
  "post_date": "2020-05-23T15:33:37.901978800Z",
  "votes": 2,
  "comment_count": 7,
  "views": 0,
  "content": "<p><code>model = models.load_model(model_path, backbone_name='resnet50')\nmodel = models.convert_model(model)</code></p>\n\n<p>When I run this code i get the error:\nModuleNotFoundError: No module named 'keras_resnet'</p>\n\n<p>For this I switched ON the Internet access in Kaggle Notebook and ran the following commands\n<code>!pip install .\n!python setup.py build_ext --inplace</code></p>\n\n<p>And then problem got solved but for this I had to keep my Internet access ON. And keeping Internet ON wont allow my submission.csv to be submitted!!</p>\n\n<p>Can anyone please guide me how to generate Predictions in Keras-retinanet without Internet Access??</p>",
  "messages": [
    {
      "id": "858558",
      "postDate": "05/23/2020 15:33:37",
      "content": "<p><code>model = models.load_model(model_path, backbone_name='resnet50')\nmodel = models.convert_model(model)</code></p>\n\n<p>When I run this code i get the error:\nModuleNotFoundError: No module named 'keras_resnet'</p>\n\n<p>For this I switched ON the Internet access in Kaggle Notebook and ran the following commands\n<code>!pip install .\n!python setup.py build_ext --inplace</code></p>\n\n<p>And then problem got solved but for this I had to keep my Internet access ON. And keeping Internet ON wont allow my submission.csv to be submitted!!</p>\n\n<p>Can anyone please guide me how to generate Predictions in Keras-retinanet without Internet Access??</p>",
      "rawMarkdown": "`model = models.load_model(model_path, backbone_name='resnet50')\nmodel = models.convert_model(model)`\n\nWhen I run this code i get the error:\nModuleNotFoundError: No module named 'keras_resnet'\n\nFor this I switched ON the Internet access in Kaggle Notebook and ran the following commands\n`!pip install .\n!python setup.py build_ext --inplace`\n\nAnd then problem got solved but for this I had to keep my Internet access ON. And keeping Internet ON wont allow my submission.csv to be submitted!!\n\nCan anyone please guide me how to generate Predictions in Keras-retinanet without Internet Access??",
      "votes": null
    },
    {
      "id": "858718",
      "postDate": "05/23/2020 18:16:37",
      "content": "<p>You can divide training and inference into two notebooks. The training notebook should output the trained model files, then create a dataset using the output of the training notebook. After you created the dataset, you can attach it to your inference notebook and load it without internet access.</p>",
      "rawMarkdown": "You can divide training and inference into two notebooks. The training notebook should output the trained model files, then create a dataset using the output of the training notebook. After you created the dataset, you can attach it to your inference notebook and load it without internet access.",
      "votes": null
    },
    {
      "id": "858800",
      "postDate": "05/23/2020 20:15:36",
      "content": "<p>In the future, try to look at existing notebooks and discussion threads. This question has been asked and answered many times already</p>",
      "rawMarkdown": "In the future, try to look at existing notebooks and discussion threads. This question has been asked and answered many times already",
      "votes": null
    },
    {
      "id": "859170",
      "postDate": "05/24/2020 07:34:52",
      "content": "<p>Just to be clear, the training notebook should output only the trained model or any other files are required? Secondly, in the inference notebook do I have to load the data same way I loaded it in Training notebook or it has to be something different as you said that create a data set using output of the training notebook? </p>",
      "rawMarkdown": "Just to be clear, the training notebook should output only the trained model or any other files are required? Secondly, in the inference notebook do I have to load the data same way I loaded it in Training notebook or it has to be something different as you said that create a data set using output of the training notebook?",
      "votes": null
    },
    {
      "id": "859173",
      "postDate": "05/24/2020 07:37:57",
      "content": "<p>I looked for existing notebooks but couldn't find anything useful! It would be great if you attach the link to any such notebooks! It will be a great help!</p>",
      "rawMarkdown": "I looked for existing notebooks but couldn't find anything useful! It would be great if you attach the link to any such notebooks! It will be a great help!",
      "votes": null
    },
    {
      "id": "859189",
      "postDate": "05/24/2020 08:09:44",
      "content": "<p>Almost any inference kernel will give a template for a good submission (<a href=\"https://www.kaggle.com/shonenkov/inference-efficientdet\">ex1</a>, <a href=\"https://www.kaggle.com/pestipeti/pytorch-starter-fasterrcnn-inference\">ex2</a>).</p>",
      "rawMarkdown": "Almost any inference kernel will give a template for a good submission ([ex1](https://www.kaggle.com/shonenkov/inference-efficientdet), [ex2](https://www.kaggle.com/pestipeti/pytorch-starter-fasterrcnn-inference)).",
      "votes": null
    },
    {
      "id": "859434",
      "postDate": "05/24/2020 12:25:27",
      "content": "<p>You can output anything you required in the training notebook. In the inference notebook, you should attach the dataset of competition, the private test set is much larger than the open one but has the same structure as the open one and you should load it in the same way.</p>",
      "rawMarkdown": "You can output anything you required in the training notebook. In the inference notebook, you should attach the dataset of competition, the private test set is much larger than the open one but has the same structure as the open one and you should load it in the same way.",
      "votes": null
    },
    {
      "id": "859497",
      "postDate": "05/24/2020 13:43:39",
      "content": "<p>So, as you said that create a dataset from the output of training model, I did that. In the training notebook, I kept my Internet ON and executed the following commands,</p>\n\n<p><code>!git clone https://github.com/fizyr/keras-retinanet.git</code>\n`%cd keras-retinanet/</p>\n\n<p>!pip install .<code>\n</code>!python setup.py build_ext --inplace`</p>\n\n<p>I had the following kerasretinanet folder in my kaggle working directory and then I trained my model and  downloaded all the files by clicking Download All.\nMy model and my kerasresnet folder were downloaded. And I uploaded the trained model and kerasretinanet folder in my Inference Notebook. But still I am getting same error which is:</p>\n\n<p>`ModuleNotFoundError                       Traceback (most recent call last)\n in \n----&gt; 1 model = models.load_model(model_path, backbone_name='resnet50')\n      2 model = models.convert_model(model)</p>\n\n<p>/kaggle/working/kerasretinanet/keras_retinanet/models/<strong>init</strong>.py in load_model(filepath, backbone_name)\n     85     \"\"\"\n     86     import keras.models\n---&gt; 87     return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)\n     88 \n     89 </p>\n\n<p>/kaggle/working/kerasretinanet/keras_retinanet/models/<strong>init</strong>.py in backbone(backbone_name)\n     55         from .senet import SeBackbone as b\n     56     elif 'resnet' in backbone_name:\n---&gt; 57         from .resnet import ResNetBackbone as b\n     58     elif 'mobilenet' in backbone_name:\n     59         from .mobilenet import MobileNetBackbone as b</p>\n\n<p>/kaggle/working/kerasretinanet/keras_retinanet/models/resnet.py in \n     17 import keras\n     18 from keras.utils import get_file\n---&gt; 19 import keras_resnet\n     20 import keras_resnet.models\n     21 </p>\n\n<p>ModuleNotFoundError: No module named 'keras_resnet'`</p>",
      "rawMarkdown": "So, as you said that create a dataset from the output of training model, I did that. In the training notebook, I kept my Internet ON and executed the following commands,\n\n`!git clone https://github.com/fizyr/keras-retinanet.git`\n`%cd keras-retinanet/\n\n!pip install .`\n`!python setup.py build_ext --inplace`\n\nI had the following kerasretinanet folder in my kaggle working directory and then I trained my model and  downloaded all the files by clicking Download All.\nMy model and my kerasresnet folder were downloaded. And I uploaded the trained model and kerasretinanet folder in my Inference Notebook. But still I am getting same error which is:\n\n`ModuleNotFoundError                       Traceback (most recent call last)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 858718,
      "author_name": "ufownl",
      "author_url": "",
      "post_date": "05/23/2020 18:16:37",
      "content": "<p>You can divide training and inference into two notebooks. The training notebook should output the trained model files, then create a dataset using the output of the training notebook. After you created the dataset, you can attach it to your inference notebook and load it without internet access.</p>",
      "votes": null,
      "replies": [
        {
          "id": 859170,
          "author_name": "aviralpamecha",
          "author_url": "",
          "post_date": "05/24/2020 07:34:52",
          "content": "<p>Just to be clear, the training notebook should output only the trained model or any other files are required? Secondly, in the inference notebook do I have to load the data same way I loaded it in Training notebook or it has to be something different as you said that create a data set using output of the training notebook? </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 859434,
          "author_name": "ufownl",
          "author_url": "",
          "post_date": "05/24/2020 12:25:27",
          "content": "<p>You can output anything you required in the training notebook. In the inference notebook, you should attach the dataset of competition, the private test set is much larger than the open one but has the same structure as the open one and you should load it in the same way.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 859497,
          "author_name": "aviralpamecha",
          "author_url": "",
          "post_date": "05/24/2020 13:43:39",
          "content": "<p>So, as you said that create a dataset from the output of training model, I did that. In the training notebook, I kept my Internet ON and executed the following commands,</p>\n\n<p><code>!git clone https://github.com/fizyr/keras-retinanet.git</code>\n`%cd keras-retinanet/</p>\n\n<p>!pip install .<code>\n</code>!python setup.py build_ext --inplace`</p>\n\n<p>I had the following kerasretinanet folder in my kaggle working directory and then I trained my model and  downloaded all the files by clicking Download All.\nMy model and my kerasresnet folder were downloaded. And I uploaded the trained model and kerasretinanet folder in my Inference Notebook. But still I am getting same error which is:</p>\n\n<p>`ModuleNotFoundError                       Traceback (most recent call last)\n in \n----&gt; 1 model = models.load_model(model_path, backbone_name='resnet50')\n      2 model = models.convert_model(model)</p>\n\n<p>/kaggle/working/kerasretinanet/keras_retinanet/models/<strong>init</strong>.py in load_model(filepath, backbone_name)\n     85     \"\"\"\n     86     import keras.models\n---&gt; 87     return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)\n     88 \n     89 </p>\n\n<p>/kaggle/working/kerasretinanet/keras_retinanet/models/<strong>init</strong>.py in backbone(backbone_name)\n     55         from .senet import SeBackbone as b\n     56     elif 'resnet' in backbone_name:\n---&gt; 57         from .resnet import ResNetBackbone as b\n     58     elif 'mobilenet' in backbone_name:\n     59         from .mobilenet import MobileNetBackbone as b</p>\n\n<p>/kaggle/working/kerasretinanet/keras_retinanet/models/resnet.py in \n     17 import keras\n     18 from keras.utils import get_file\n---&gt; 19 import keras_resnet\n     20 import keras_resnet.models\n     21 </p>\n\n<p>ModuleNotFoundError: No module named 'keras_resnet'`</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 858800,
      "author_name": "matthewmasters",
      "author_url": "",
      "post_date": "05/23/2020 20:15:36",
      "content": "<p>In the future, try to look at existing notebooks and discussion threads. This question has been asked and answered many times already</p>",
      "votes": null,
      "replies": [
        {
          "id": 859173,
          "author_name": "aviralpamecha",
          "author_url": "",
          "post_date": "05/24/2020 07:37:57",
          "content": "<p>I looked for existing notebooks but couldn't find anything useful! It would be great if you attach the link to any such notebooks! It will be a great help!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 859189,
          "author_name": "matthewmasters",
          "author_url": "",
          "post_date": "05/24/2020 08:09:44",
          "content": "<p>Almost any inference kernel will give a template for a good submission (<a href=\"https://www.kaggle.com/shonenkov/inference-efficientdet\">ex1</a>, <a href=\"https://www.kaggle.com/pestipeti/pytorch-starter-fasterrcnn-inference\">ex2</a>).</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "858558": "`model = models.load_model(model_path, backbone_name='resnet50')\nmodel = models.convert_model(model)`\n\nWhen I run this code i get the error:\nModuleNotFoundError: No module named 'keras_resnet'\n\nFor this I switched ON the Internet access in Kaggle Notebook and ran the following commands\n`!pip install .\n!python setup.py build_ext --inplace`\n\nAnd then problem got solved but for this I had to keep my Internet access ON. And keeping Internet ON wont allow my submission.csv to be submitted!!\n\nCan anyone please guide me how to generate Predictions in Keras-retinanet without Internet Access??",
    "858718": "You can divide training and inference into two notebooks. The training notebook should output the trained model files, then create a dataset using the output of the training notebook. After you created the dataset, you can attach it to your inference notebook and load it without internet access.",
    "858800": "In the future, try to look at existing notebooks and discussion threads. This question has been asked and answered many times already",
    "859170": "Just to be clear, the training notebook should output only the trained model or any other files are required? Secondly, in the inference notebook do I have to load the data same way I loaded it in Training notebook or it has to be something different as you said that create a data set using output of the training notebook?",
    "859173": "I looked for existing notebooks but couldn't find anything useful! It would be great if you attach the link to any such notebooks! It will be a great help!",
    "859189": "Almost any inference kernel will give a template for a good submission ([ex1](https://www.kaggle.com/shonenkov/inference-efficientdet), [ex2](https://www.kaggle.com/pestipeti/pytorch-starter-fasterrcnn-inference)).",
    "859434": "You can output anything you required in the training notebook. In the inference notebook, you should attach the dataset of competition, the private test set is much larger than the open one but has the same structure as the open one and you should load it in the same way.",
    "859497": "So, as you said that create a dataset from the output of training model, I did that. In the training notebook, I kept my Internet ON and executed the following commands,\n\n`!git clone https://github.com/fizyr/keras-retinanet.git`\n`%cd keras-retinanet/\n\n!pip install .`\n`!python setup.py build_ext --inplace`\n\nI had the following kerasretinanet folder in my kaggle working directory and then I trained my model and  downloaded all the files by clicking Download All.\nMy model and my kerasresnet folder were downloaded. And I uploaded the trained model and kerasretinanet folder in my Inference Notebook. But still I am getting same error which is:\n\n`ModuleNotFoundError                       Traceback (most recent call last)"
  },
  "source": "meta"
}