{
  "id": 45391,
  "title": "'imagenet_utils' is not defined when reloading model to predict only",
  "url": "/competitions/cdiscount-image-classification-challenge/discussion/45391",
  "author_name": "",
  "post_date": "2017-12-10T15:50:51.111847800Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>In Keras, after training successfully Xception with pretrained imagenet weights, I try to tun another script that loads that saved model only to predict. I get the following error, can anyone help me please?</p>\n\n<p><code>\nFile \"models/test_keras.py\", line 85, in &lt;module&gt;\n    model = load_model(model)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/models.py\", line 240, in load_model\n    model = model_from_config(model_config, custom_objects=custom_objects)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/models.py\", line 314, in model_from_config\n    return layer_module.deserialize(config, custom_objects=custom_objects)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/layers/__init__.py\", line 55, in deserialize\n    printable_module_name='layer')\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/utils/generic_utils.py\", line 140, in deserialize_keras_object\n    list(custom_objects.items())))\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/engine/topology.py\", line 2500, in from_config\n    process_node(layer, node_data)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/engine/topology.py\", line 2457, in process_node\n    layer(input_tensors[0], **kwargs)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/engine/topology.py\", line 603, in __call__\n    output = self.call(inputs, **kwargs)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/layers/core.py\", line 651, in call\n    return self.function(inputs, **arguments)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/applications/xception.py\", line 280, in preprocess_input\n    return imagenet_utils.preprocess_input(x, mode='tf')\nNameError: name 'imagenet_utils' is not defined\n</code></p>",
  "messages": [
    {
      "id": "255931",
      "postDate": "12/10/2017 15:50:51",
      "content": "<p>In Keras, after training successfully Xception with pretrained imagenet weights, I try to tun another script that loads that saved model only to predict. I get the following error, can anyone help me please?</p>\n\n<p><code>\nFile \"models/test_keras.py\", line 85, in &lt;module&gt;\n    model = load_model(model)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/models.py\", line 240, in load_model\n    model = model_from_config(model_config, custom_objects=custom_objects)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/models.py\", line 314, in model_from_config\n    return layer_module.deserialize(config, custom_objects=custom_objects)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/layers/__init__.py\", line 55, in deserialize\n    printable_module_name='layer')\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/utils/generic_utils.py\", line 140, in deserialize_keras_object\n    list(custom_objects.items())))\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/engine/topology.py\", line 2500, in from_config\n    process_node(layer, node_data)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/engine/topology.py\", line 2457, in process_node\n    layer(input_tensors[0], **kwargs)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/engine/topology.py\", line 603, in __call__\n    output = self.call(inputs, **kwargs)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/layers/core.py\", line 651, in call\n    return self.function(inputs, **arguments)\n  File \"/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/applications/xception.py\", line 280, in preprocess_input\n    return imagenet_utils.preprocess_input(x, mode='tf')\nNameError: name 'imagenet_utils' is not defined\n</code></p>",
      "rawMarkdown": "In Keras, after training successfully Xception with pretrained imagenet weights, I try to tun another script that loads that saved model only to predict. I get the following error, can anyone help me please?\n\n```\nFile \"models/test_keras.py\", line 85, in",
      "votes": null
    },
    {
      "id": "256006",
      "postDate": "12/10/2017 22:51:23",
      "content": "<p>When I've run into similar errors it was because the model was previously trained on a different version of keras.  If it's not a version mismatch you could try directly importing the <code>imagenet_utils</code> to see if that helps.</p>",
      "rawMarkdown": "When I've run into similar errors it was because the model was previously trained on a different version of keras.  If it's not a version mismatch you could try directly importing the `imagenet_utils` to see if that helps.",
      "votes": null
    },
    {
      "id": "256007",
      "postDate": "12/10/2017 23:03:03",
      "content": "<p>Thanks for your answer. However, I don't think that's the problem since I trained the model in the same virtualenv, with the same Keras version.</p>\n\n<p>I have tried to go under <code>/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/applications/xception.py</code> and debug it from there. However, load_model does not really call <strong>my</strong> modified version of the code. Idk why that happens</p>",
      "rawMarkdown": "Thanks for your answer. However, I don't think that's the problem since I trained the model in the same virtualenv, with the same Keras version.\n\nI have tried to go under `/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/applications/xception.py` and debug it from there. However, load_model does not really call **my** modified version of the code. Idk why that happens",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 256006,
      "author_name": "bierson",
      "author_url": "",
      "post_date": "12/10/2017 22:51:23",
      "content": "<p>When I've run into similar errors it was because the model was previously trained on a different version of keras.  If it's not a version mismatch you could try directly importing the <code>imagenet_utils</code> to see if that helps.</p>",
      "votes": null,
      "replies": [
        {
          "id": 256007,
          "author_name": "skinish",
          "author_url": "",
          "post_date": "12/10/2017 23:03:03",
          "content": "<p>Thanks for your answer. However, I don't think that's the problem since I trained the model in the same virtualenv, with the same Keras version.</p>\n\n<p>I have tried to go under <code>/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/applications/xception.py</code> and debug it from there. However, load_model does not really call <strong>my</strong> modified version of the code. Idk why that happens</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "255931": "In Keras, after training successfully Xception with pretrained imagenet weights, I try to tun another script that loads that saved model only to predict. I get the following error, can anyone help me please?\n\n```\nFile \"models/test_keras.py\", line 85, in",
    "256006": "When I've run into similar errors it was because the model was previously trained on a different version of keras.  If it's not a version mismatch you could try directly importing the `imagenet_utils` to see if that helps.",
    "256007": "Thanks for your answer. However, I don't think that's the problem since I trained the model in the same virtualenv, with the same Keras version.\n\nI have tried to go under `/afs/l2f.inesc-id.pt/home/jlages/Cdiscount_Kaggle/venv/lib/python3.6/site-packages/keras/applications/xception.py` and debug it from there. However, load_model does not really call **my** modified version of the code. Idk why that happens"
  },
  "source": "meta"
}