title: Using a pytorch model for inference
body: <p>I am using the fastai library (<a href="http://fast.ai" rel="nofollow noreferrer">fast.ai</a>) to train an image classifier. The model created by fastai is actually a pytorch model.</p>
  
  <pre><code>type(model)
  &lt;class 'torch.nn.modules.container.Sequential'&gt;
  </code></pre>
  
  <p>Now, I want to use this model from pytorch for inference. Here is my code so far:</p>
  
  <pre><code>torch.save(model,"./torch_model_v1")
  the_model = torch.load("./torch_model_v1")
  the_model.eval() # shows the entire network architecture
  </code></pre>
  
  <p>Based on the example shown here: <a href="http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#sphx-glr-beginner-data-loading-tutorial-py" rel="nofollow noreferrer">http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#sphx-glr-beginner-data-loading-tutorial-py</a>, I understand that I need to write my own data loading class which will override some of the functions in the Dataset class. But what is not clear to me is the transformations that I need to apply at test time? In particular, how do I normalize the images at test time?</p>
  
  <p>Another question: is my approach of saving and loading the model in pytorch fine? I read in the tutorial here: <a href="http://pytorch.org/docs/master/notes/serialization.html" rel="nofollow noreferrer">http://pytorch.org/docs/master/notes/serialization.html</a> that the approach that I have used is not recommended. The reason is not clear though.</p>