Created
December 23, 2021 21:02
-
-
Save vinimonteiro/a23ba2cc716bf31bdaef4c82c696fcb7 to your computer and use it in GitHub Desktop.
Client calls MNIST service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn.functional as F | |
import torchvision | |
from torchvision import transforms, datasets | |
import matplotlib.pyplot as plt | |
import torch.nn as nn | |
import sys | |
import json | |
import requests | |
# Loading and transforming the dataset | |
test = datasets.MNIST("", train=False, download=True, | |
transform = transforms.Compose([transforms.ToTensor()])) | |
testset = torch.utils.data.DataLoader(test, batch_size=15, shuffle=True) | |
for data in testset: | |
X, y = data | |
digit = X[6] | |
plt.imshow(digit.view(28,28)) | |
plt.show() | |
# call guess service | |
input = json.dumps(digit.tolist()) | |
response = requests.post("http://127.0.0.1:8888/guess", json=input).text | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment