Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Training set not showing in matplotlib

$
0
0

For some reason my training set is not showing as a matplotlib graph, I am using the torchvision dataset MNIST. Sorry if my code is not the most efficient, just starting pytorch.

The code is running without any errors however the graph of data won't be shown. I tried doing the .view() to reshape the data shape from a (1, 28, 28) to a (28, 28) that will be allowed, however the data won't be shown. Here is my code:

import torchimport torchvisionimport matplotlib.pyplot as pltfrom torchvision import transforms, datasetstrain = datasets.MNIST("", train=True, download=True,                       transform= transforms.Compose([transforms.ToTensor()]))test = datasets.MNIST("", train=False, download=True,                       transform= transforms.Compose([transforms.ToTensor()]))trainset = torch.utils.data.DataLoader(train, batch_size=10, shuffle=True)testset = torch.utils.data.DataLoader(test, batch_size=10, shuffle=True)for data in trainset:    print(data)    breakx, y = data[0][0], data[1][0]print(y)plt.imshow(data[0][0].view(28,28))plt.show()

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>