{
  "id": 160375,
  "title": "How can I save a model?",
  "url": "/competitions/alaska2-image-steganalysis/discussion/160375",
  "author_name": "",
  "post_date": "2020-06-21T04:00:57.076858700Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<p>How can I save a model and re-use the weights in a fresh kernel?</p>",
  "messages": [
    {
      "id": "895029",
      "postDate": "06/21/2020 04:00:57",
      "content": "<p>How can I save a model and re-use the weights in a fresh kernel?</p>",
      "rawMarkdown": "How can I save a model and re-use the weights in a fresh kernel?",
      "votes": null
    },
    {
      "id": "896084",
      "postDate": "06/21/2020 20:08:42",
      "content": "<p>For keras:\nmodel.save_weights(filepath)\nmodel.load_weights(filepath)</p>\n\n<p>For pytorch:\ntorch.save(model.state_dict(), filepath)\nmodel.load_state_dict(torch.load(filepath))</p>",
      "rawMarkdown": "For keras:\nmodel.save_weights(filepath)\nmodel.load_weights(filepath)\n\nFor pytorch:\ntorch.save(model.state_dict(), filepath)\nmodel.load_state_dict(torch.load(filepath))",
      "votes": null
    },
    {
      "id": "902048",
      "postDate": "06/25/2020 22:19:03",
      "content": "<p><a href=\"/zaber666\">@zaber666</a> \nthanks for the information. when I save it, where does the model file reside? As in, in a new kernel, what would be the file path? Sorry if I am missing sth very simple</p>",
      "rawMarkdown": "zaber666 \nthanks for the information. when I save it, where does the model file reside? As in, in a new kernel, what would be the file path? Sorry if I am missing sth very simple",
      "votes": null
    },
    {
      "id": "902058",
      "postDate": "06/25/2020 22:33:31",
      "content": "<p>If you are training in kaggle and if use filepath = 'model.pth' then you will find it on the '/kaggle/working' directory.\nIf you are training in google colab then first you have to mount the drive with your notebook and use filepath = folderpath + '/model.pth'. You will find the file in your given folder path.</p>",
      "rawMarkdown": "If you are training in kaggle and if use filepath = 'model.pth' then you will find it on the '/kaggle/working' directory.\nIf you are training in google colab then first you have to mount the drive with your notebook and use filepath = folderpath + '/model.pth'. You will find the file in your given folder path.",
      "votes": null
    },
    {
      "id": "916547",
      "postDate": "07/05/2020 18:33:01",
      "content": "<p>thanks <a href=\"/zaber666\">@zaber666</a> </p>",
      "rawMarkdown": "thanks @zaber666",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 896084,
      "author_name": "zaber666",
      "author_url": "",
      "post_date": "06/21/2020 20:08:42",
      "content": "<p>For keras:\nmodel.save_weights(filepath)\nmodel.load_weights(filepath)</p>\n\n<p>For pytorch:\ntorch.save(model.state_dict(), filepath)\nmodel.load_state_dict(torch.load(filepath))</p>",
      "votes": null,
      "replies": [
        {
          "id": 902048,
          "author_name": "vaibhavbansal",
          "author_url": "",
          "post_date": "06/25/2020 22:19:03",
          "content": "<p><a href=\"/zaber666\">@zaber666</a> \nthanks for the information. when I save it, where does the model file reside? As in, in a new kernel, what would be the file path? Sorry if I am missing sth very simple</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 902058,
          "author_name": "zaber666",
          "author_url": "",
          "post_date": "06/25/2020 22:33:31",
          "content": "<p>If you are training in kaggle and if use filepath = 'model.pth' then you will find it on the '/kaggle/working' directory.\nIf you are training in google colab then first you have to mount the drive with your notebook and use filepath = folderpath + '/model.pth'. You will find the file in your given folder path.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 916547,
          "author_name": "vaibhavbansal",
          "author_url": "",
          "post_date": "07/05/2020 18:33:01",
          "content": "<p>thanks <a href=\"/zaber666\">@zaber666</a> </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "895029": "How can I save a model and re-use the weights in a fresh kernel?",
    "896084": "For keras:\nmodel.save_weights(filepath)\nmodel.load_weights(filepath)\n\nFor pytorch:\ntorch.save(model.state_dict(), filepath)\nmodel.load_state_dict(torch.load(filepath))",
    "902048": "zaber666 \nthanks for the information. when I save it, where does the model file reside? As in, in a new kernel, what would be the file path? Sorry if I am missing sth very simple",
    "902058": "If you are training in kaggle and if use filepath = 'model.pth' then you will find it on the '/kaggle/working' directory.\nIf you are training in google colab then first you have to mount the drive with your notebook and use filepath = folderpath + '/model.pth'. You will find the file in your given folder path.",
    "916547": "thanks @zaber666"
  },
  "source": "meta"
}