Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created August 19, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/90e5dbea343c492cbc44b650cf89b711 to your computer and use it in GitHub Desktop.
Save amankharwal/90e5dbea343c492cbc44b650cf89b711 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
with torch.no_grad(): # we don't need gradients in the testing phase
if torch.cuda.is_available():
predicted = model(Variable(torch.from_numpy(x_train).cuda())).cpu().data.numpy()
else:
predicted = model(Variable(torch.from_numpy(x_train))).data.numpy()
print(predicted)
plt.clf()
plt.plot(x_train, y_train, 'go', label='True data', alpha=0.5)
plt.plot(x_train, predicted, '--', label='Predictions', alpha=0.5)
plt.legend(loc='best')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment