How to add functions to save and load model?

username: tanks
cooked: <p>Hi,</p>
<p>I am very new to pytorch.</p>
<p>I am trying to use the below algo for my project.<br>
How to add functions to save and load model ?</p>
<p>I want o save the model.<br>
Then load the model and use the predict function.</p>
<p>Any sample code for me to learn and use ?</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/KDD-OpenSource/DeepADoTS/blob/master/src/algorithms/lstm_ad.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/KDD-OpenSource/DeepADoTS/blob/master/src/algorithms/lstm_ad.py" target="_blank" rel="nofollow noopener">KDD-OpenSource/DeepADoTS/blob/master/src/algorithms/lstm_ad.py</a></h4>
<pre><code class="lang-py">import numpy as np
import pandas as pd
import torch
from scipy.stats import multivariate_normal
from torch.autograd import Variable
from tqdm import trange

from .algorithm_utils import Algorithm, PyTorchUtils


class LSTMAD(Algorithm, PyTorchUtils):
    """ LSTM-AD implementation using PyTorch.
    The interface of the class is sklearn-like.
    """

    def __init__(self, len_in=1, len_out=10, num_epochs=100, lr=1e-3, batch_size=1,
                 seed: int=None, gpu: int=None, details=True):
        Algorithm.__init__(self, __name__, 'LSTM-AD', seed, details=details)
        PyTorchUtils.__init__(self, seed, gpu)
        self.num_epochs = num_epochs
</code></pre>

  This file has been truncated. <a href="https://github.com/KDD-OpenSource/DeepADoTS/blob/master/src/algorithms/lstm_ad.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>Please help.</p>
<p>Thank you</p>

username: InnovArul
cooked: <p>Many useful utility functions are in this file:</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/KaiyangZhou/deep-person-reid/blob/master/torchreid/utils/torchtools.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/KaiyangZhou/deep-person-reid/blob/master/torchreid/utils/torchtools.py" target="_blank" rel="nofollow noopener">KaiyangZhou/deep-person-reid/blob/master/torchreid/utils/torchtools.py</a></h4>
<pre><code class="lang-py">from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

__all__ = ['save_checkpoint', 'load_checkpoint', 'resume_from_checkpoint',
           'open_all_layers', 'open_specified_layers', 'count_num_param',
           'load_pretrained_weights']

from collections import OrderedDict
import shutil
import warnings
import os
import os.path as osp
from functools import partial
import pickle

import torch
import torch.nn as nn

from .tools import mkdir_if_missing
</code></pre>

  This file has been truncated. <a href="https://github.com/KaiyangZhou/deep-person-reid/blob/master/torchreid/utils/torchtools.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>Thanks to KaiyangZhou@github.</p>