{
  "id": 303344,
  "title": "Predicting from the saved model.",
  "url": "/competitions/tensorflow-great-barrier-reef/discussion/303344",
  "author_name": "",
  "post_date": "2022-01-27T06:00:19.191373400Z",
  "votes": 1,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I have referenced some of the notebooks and trained the model.<br>\nwith faster R-CNN in TensorFlow.<br>\nI have the saved_model.<br>\nSo can anyone help me? how to predict from the saved_model that I have.<br>\nI have tried tf.Keras.load_model(\"saved_model\")<br>\nbut It is  warning that keras_metadata.pb file is missing.</p>\n<p>Can anyone share how to predict.</p>",
  "messages": [
    {
      "id": "1665779",
      "postDate": "01/27/2022 06:00:19",
      "content": "<p>I have referenced some of the notebooks and trained the model.<br>\nwith faster R-CNN in TensorFlow.<br>\nI have the saved_model.<br>\nSo can anyone help me? how to predict from the saved_model that I have.<br>\nI have tried tf.Keras.load_model(\"saved_model\")<br>\nbut It is  warning that keras_metadata.pb file is missing.</p>\n<p>Can anyone share how to predict.</p>",
      "rawMarkdown": "I have referenced some of the notebooks and trained the model.\nwith faster R-CNN in TensorFlow.\nI have the saved_model.\nSo can anyone help me? how to predict from the saved_model that I have.\nI have tried tf.Keras.load_model(\"saved_model\")\nbut It is  warning that keras_metadata.pb file is missing.\n\nCan anyone share how to predict.",
      "votes": null
    },
    {
      "id": "1665832",
      "postDate": "01/27/2022 06:36:52",
      "content": "<p>There are several two options to save the model in TensorFlow. One of them - is the SavedModel format.</p>\n<p>SavedModel is the more comprehensive save format that saves the model architecture, weights, and the traced Tensorflow subgraphs of the call functions. This enables Keras to restore both built-in layers as well as custom objects.<br>\nSaving model in that format creates a folder named <code>saved_model</code>, containing the following:</p>\n<p><code>assets  keras_metadata.pb  saved_model.pb  variables</code></p>\n<p>The model architecture and training configuration (including the optimizer, losses, and metrics) are stored in saved_model.pb. The weights are saved in the variables/ directory.</p>\n<p>According to <a href=\"https://github.com/tensorflow/tensorflow/issues/46385\" target=\"_blank\">that issue on GitHub</a>:</p>\n<p><code>This is intended behavior and the warning is to encourage users to use model.save instead of tf.saved_model.save when saving keras models.</code></p>\n<p>Does your notebook use the same TF version?</p>",
      "rawMarkdown": "There are several two options to save the model in TensorFlow. One of them - is the SavedModel format.\n\nSavedModel is the more comprehensive save format that saves the model architecture, weights, and the traced Tensorflow subgraphs of the call functions. This enables Keras to restore both built-in layers as well as custom objects.\nSaving model in that format creates a folder named `saved_model`, containing the following:\n\n```assets  keras_metadata.pb  saved_model.pb  variables```\n\nThe model architecture and training configuration (including the optimizer, losses, and metrics) are stored in saved_model.pb. The weights are saved in the variables/ directory.\n\n\nAccording to [that issue on GitHub](https://github.com/tensorflow/tensorflow/issues/46385):\n\n```This is intended behavior and the warning is to encourage users to use model.save instead of tf.saved_model.save when saving keras models.```\n\nDoes your notebook use the same TF version?",
      "votes": null
    },
    {
      "id": "1665902",
      "postDate": "01/27/2022 08:03:26",
      "content": "<p>Yes sir. It is the same version. <a href=\"https://www.kaggle.com/captainabhijeeth/cots-tensorflow-fasterrcnn/notebook\" target=\"_blank\">https://www.kaggle.com/captainabhijeeth/cots-tensorflow-fasterrcnn/notebook</a></p>",
      "rawMarkdown": "Yes sir. It is the same version. https://www.kaggle.com/captainabhijeeth/cots-tensorflow-fasterrcnn/notebook",
      "votes": null
    },
    {
      "id": "1667919",
      "postDate": "01/29/2022 04:46:08",
      "content": "<p>Yes, I got what was wrong with my model. I have downloaded a pre-trained model which initially didn't provide keras_meatadata.pb. And after the training of the model was not saved from the base instead it altered the wights.<br>\nAnd to predict from the saved model.<br>\nthe naive approach of :<br>\ntf.Keras.load_model(\"saved_model\") #will not work</p>\n<p>we have to use:<br>\nmodel=tf.saved_model.load('saved_model')<br>\nAnd to predict <br>\nprediction=model()</p>\n<p>OR you can predict using an inference graph.</p>\n<p>I know this is a simple thing. But think will help newbies like me. It was fun exploring the core code to see what was happening. <br>\nThanks to <a href=\"https://www.kaggle.com/meowmeowmeowmeowmeow\" target=\"_blank\">@meowmeowmeowmeowmeow</a> and <a href=\"https://www.kaggle.com/datastrophy\" target=\"_blank\">@datastrophy</a> </p>",
      "rawMarkdown": "Yes, I got what was wrong with my model. I have downloaded a pre-trained model which initially didn't provide keras_meatadata.pb. And after the training of the model was not saved from the base instead it altered the wights.\nAnd to predict from the saved model.\nthe naive approach of :\ntf.Keras.load_model(\"saved_model\") #will not work\n\nwe have to use:\nmodel=tf.saved_model.load('saved_model')\nAnd to predict \nprediction=model(<image tensor>)\n\nOR you can predict using an inference graph.\n\nI know this is a simple thing. But think will help newbies like me. It was fun exploring the core code to see what was happening. \nThanks to @meowmeowmeowmeowmeow and @datastrophy",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1665832,
      "author_name": "meowmeowmeowmeowmeow",
      "author_url": "",
      "post_date": "01/27/2022 06:36:52",
      "content": "<p>There are several two options to save the model in TensorFlow. One of them - is the SavedModel format.</p>\n<p>SavedModel is the more comprehensive save format that saves the model architecture, weights, and the traced Tensorflow subgraphs of the call functions. This enables Keras to restore both built-in layers as well as custom objects.<br>\nSaving model in that format creates a folder named <code>saved_model</code>, containing the following:</p>\n<p><code>assets  keras_metadata.pb  saved_model.pb  variables</code></p>\n<p>The model architecture and training configuration (including the optimizer, losses, and metrics) are stored in saved_model.pb. The weights are saved in the variables/ directory.</p>\n<p>According to <a href=\"https://github.com/tensorflow/tensorflow/issues/46385\" target=\"_blank\">that issue on GitHub</a>:</p>\n<p><code>This is intended behavior and the warning is to encourage users to use model.save instead of tf.saved_model.save when saving keras models.</code></p>\n<p>Does your notebook use the same TF version?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1665902,
      "author_name": "captainabhijeeth",
      "author_url": "",
      "post_date": "01/27/2022 08:03:26",
      "content": "<p>Yes sir. It is the same version. <a href=\"https://www.kaggle.com/captainabhijeeth/cots-tensorflow-fasterrcnn/notebook\" target=\"_blank\">https://www.kaggle.com/captainabhijeeth/cots-tensorflow-fasterrcnn/notebook</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1667919,
      "author_name": "captainabhijeeth",
      "author_url": "",
      "post_date": "01/29/2022 04:46:08",
      "content": "<p>Yes, I got what was wrong with my model. I have downloaded a pre-trained model which initially didn't provide keras_meatadata.pb. And after the training of the model was not saved from the base instead it altered the wights.<br>\nAnd to predict from the saved model.<br>\nthe naive approach of :<br>\ntf.Keras.load_model(\"saved_model\") #will not work</p>\n<p>we have to use:<br>\nmodel=tf.saved_model.load('saved_model')<br>\nAnd to predict <br>\nprediction=model()</p>\n<p>OR you can predict using an inference graph.</p>\n<p>I know this is a simple thing. But think will help newbies like me. It was fun exploring the core code to see what was happening. <br>\nThanks to <a href=\"https://www.kaggle.com/meowmeowmeowmeowmeow\" target=\"_blank\">@meowmeowmeowmeowmeow</a> and <a href=\"https://www.kaggle.com/datastrophy\" target=\"_blank\">@datastrophy</a> </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1665779": "I have referenced some of the notebooks and trained the model.\nwith faster R-CNN in TensorFlow.\nI have the saved_model.\nSo can anyone help me? how to predict from the saved_model that I have.\nI have tried tf.Keras.load_model(\"saved_model\")\nbut It is  warning that keras_metadata.pb file is missing.\n\nCan anyone share how to predict.",
    "1665832": "There are several two options to save the model in TensorFlow. One of them - is the SavedModel format.\n\nSavedModel is the more comprehensive save format that saves the model architecture, weights, and the traced Tensorflow subgraphs of the call functions. This enables Keras to restore both built-in layers as well as custom objects.\nSaving model in that format creates a folder named `saved_model`, containing the following:\n\n```assets  keras_metadata.pb  saved_model.pb  variables```\n\nThe model architecture and training configuration (including the optimizer, losses, and metrics) are stored in saved_model.pb. The weights are saved in the variables/ directory.\n\n\nAccording to [that issue on GitHub](https://github.com/tensorflow/tensorflow/issues/46385):\n\n```This is intended behavior and the warning is to encourage users to use model.save instead of tf.saved_model.save when saving keras models.```\n\nDoes your notebook use the same TF version?",
    "1665902": "Yes sir. It is the same version. https://www.kaggle.com/captainabhijeeth/cots-tensorflow-fasterrcnn/notebook",
    "1667919": "Yes, I got what was wrong with my model. I have downloaded a pre-trained model which initially didn't provide keras_meatadata.pb. And after the training of the model was not saved from the base instead it altered the wights.\nAnd to predict from the saved model.\nthe naive approach of :\ntf.Keras.load_model(\"saved_model\") #will not work\n\nwe have to use:\nmodel=tf.saved_model.load('saved_model')\nAnd to predict \nprediction=model(<image tensor>)\n\nOR you can predict using an inference graph.\n\nI know this is a simple thing. But think will help newbies like me. It was fun exploring the core code to see what was happening. \nThanks to @meowmeowmeowmeowmeow and @datastrophy"
  },
  "source": "meta"
}