title: How to evaluate a single image in PyTorch model?
body: <p>I used this code to train a model:</p>
  
  <pre><code>def train(model, epochs):
      for epoch in range(epochs):
          for idx, batch in enumerate(train_loader):
              x, bndbox = batch    # unpack batch
              pred_bndbox = model(x)# forward pass
              #print('label:', bndbox, 'prediction:', pred_bndbox)
              loss = criterion(pred_bndbox, bndbox)     # compute loss for this batch
              optimiser.zero_grad()# zero gradients of optimiser
              loss.backward()     # backward pass (find rate of change of loss with respect to model parameters)
              optimiser.step()# take optimisation step
              print('Epoch:', epoch, 'Batch:', idx, 'Loss:', loss.item())
              writer.add_scalar('DETECTION Loss/Train', loss, epoch*len(train_loader) + idx)    # write loss to a graph
  
  train(cnn, epochs)
  
  torch.save(cnn.state_dict(), str(time.time()))# save model
  
  def visualise(model, n):
      model.eval()
      for idx, batch in enumerate(test_loader):
          x, y = batch
          pred_bndbox = model(x)
          S40dataset.show(batch, pred_bndbox=pred_bndbox)
          if idx == n:
              break
  </code></pre>
  
  <p>How do I evaluate the model prediction on a single image to check the operation of the neural network?</p>