title: Load/test previously trained and saved neural network Python
body: <p>I define my neural network</p>
  <pre><code>
  class Classifier(nn.Module):
      def __init__(self):
          super().__init__()
          self.fc1 = nn.Linear(784, 256)
          self.fc2 = nn.Linear(256, 128)
          self.fc3 = nn.Linear(128, 64)
          self.fc4 = nn.Linear(64, 10)
          
      def forward(self, x):
          # make sure input tensor is flattened
          x = x.view(x.shape[0], -1)
          
          x = F.relu(self.fc1(x))
          x = F.relu(self.fc2(x))
          x = F.relu(self.fc3(x))
          x = F.log_softmax(self.fc4(x), dim=1)
          
          return x
  
  model = Classifier()
  </code></pre>
  <p>I train the neural network</p>
  <p>I save the trained neural net:</p>
  <pre><code>checkpoint = {'input_size': 784,
                'output_size': 10,
                'hidden_layers': [256, 128, 64],
                'state_dict': model.state_dict()}
  
  torch.save(checkpoint, 'checkpoint.pth')
  state_dict = torch.load('checkpoint.pth')
  </code></pre>
  <p>when I try to load the saved neural network, I get an error</p>
  <pre><code>def load_checkpoint(filepath):
      checkpoint = torch.load(filepath)
      # I believe the error is in the line directly below
      model_b = model(checkpoint['input_size'], checkpoint['output_size'], checkpoint['hidden_layers'])
      model_b.load_state_dict(checkpoint['state_dict'])
      return model_b
  
  model_b = load_checkpoint('checkpoint.pth')
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>TypeError: forward() takes 2 positional arguments but 4 were given
  </code></pre>