def visualize_model_predictions(model,img_path): was_training = model.training model.eval() img = Image.open(img_path) img = data_transforms['val'](img) img = img.unsqueeze(0) img = img.to(device) with [torch.no_grad](https://docs.pytorch.org/docs/stable/generated/torch.no_grad.html#torch.no_grad "torch.no_grad")(): outputs = model(img) _, preds = [torch.max](https://docs.pytorch.org/docs/stable/generated/torch.max.html#torch.max "torch.max")(outputs, 1) ax = plt.subplot(2,2,1) ax.axis('off') ax.set_title(f'Predicted: {class_names[preds[0]]}') imshow(img.cpu().data[0]) model.train(mode=was_training)