{
  "id": 167544,
  "title": "(tf.keras) How to release kernel RAM during inference?",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/167544",
  "author_name": "",
  "post_date": "2020-07-17T03:30:27.076828900Z",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Use tf.data.TFRecordDataset and model.predict in inference, but consumed RAM keep increasing duing inference, need help!!!! How to release dataset after a prediction in tf.keras? Thanks.</p>",
  "messages": [
    {
      "id": "932401",
      "postDate": "07/17/2020 03:30:27",
      "content": "<p>Use tf.data.TFRecordDataset and model.predict in inference, but consumed RAM keep increasing duing inference, need help!!!! How to release dataset after a prediction in tf.keras? Thanks.</p>",
      "rawMarkdown": "Use tf.data.TFRecordDataset and model.predict in inference, but consumed RAM keep increasing duing inference, need help!!!! How to release dataset after a prediction in tf.keras? Thanks.",
      "votes": null
    },
    {
      "id": "932431",
      "postDate": "07/17/2020 04:18:50",
      "content": "<p>General python memory tips: wrap your code into functions so that temporary variables are released once function call completes, delete unused variables explicitly, and call gc.collect()</p>\n\n<p><code>\nimport gc\ndel largeVariable\ngc.collect()\n</code></p>\n\n<p>You can also <a href=\"https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session\">clear a session</a> and create another one:\ntf.keras.backend.clear_session()</p>",
      "rawMarkdown": "General python memory tips: wrap your code into functions so that temporary variables are released once function call completes, delete unused variables explicitly, and call gc.collect()\n\n```\nimport gc\ndel largeVariable\ngc.collect()\n```\n\nYou can also [clear a session](https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session) and create another one:\ntf.keras.backend.clear_session()",
      "votes": null
    },
    {
      "id": "932472",
      "postDate": "07/17/2020 04:51:26",
      "content": "<p>Thanks for your reply, I had tried to wrap inference code into function and delete large variables. I think I must have made some mistakes in my code, thank you for your help.😄 </p>",
      "rawMarkdown": "Thanks for your reply, I had tried to wrap inference code into function and delete large variables. I think I must have made some mistakes in my code, thank you for your help.😄",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 932431,
      "author_name": "sirishks",
      "author_url": "",
      "post_date": "07/17/2020 04:18:50",
      "content": "<p>General python memory tips: wrap your code into functions so that temporary variables are released once function call completes, delete unused variables explicitly, and call gc.collect()</p>\n\n<p><code>\nimport gc\ndel largeVariable\ngc.collect()\n</code></p>\n\n<p>You can also <a href=\"https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session\">clear a session</a> and create another one:\ntf.keras.backend.clear_session()</p>",
      "votes": null,
      "replies": [
        {
          "id": 932472,
          "author_name": "anthonymarcz",
          "author_url": "",
          "post_date": "07/17/2020 04:51:26",
          "content": "<p>Thanks for your reply, I had tried to wrap inference code into function and delete large variables. I think I must have made some mistakes in my code, thank you for your help.😄 </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "932401": "Use tf.data.TFRecordDataset and model.predict in inference, but consumed RAM keep increasing duing inference, need help!!!! How to release dataset after a prediction in tf.keras? Thanks.",
    "932431": "General python memory tips: wrap your code into functions so that temporary variables are released once function call completes, delete unused variables explicitly, and call gc.collect()\n\n```\nimport gc\ndel largeVariable\ngc.collect()\n```\n\nYou can also [clear a session](https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session) and create another one:\ntf.keras.backend.clear_session()",
    "932472": "Thanks for your reply, I had tried to wrap inference code into function and delete large variables. I think I must have made some mistakes in my code, thank you for your help.😄"
  },
  "source": "meta"
}