Maison >développement back-end >Tutoriel Python >QMNIST dans PyTorch
Achetez-moi un café☕
*Mon message explique QMNIST.
QMNIST() peut utiliser l'ensemble de données QMNIST comme indiqué ci-dessous :
*Mémos :
from torchvision.datasets import QMNIST train_data = QMNIST( root="data" ) train_data = QMNIST( root="data", what=None, compat=True, train=True, transform=None, target_transform=None, download=False ) train_data = QMNIST( root="data", what="train", train=False ) test_data1 = QMNIST( root="data", train=False ) test_data1 = QMNIST( root="data", what="test", train=True ) test_data2 = QMNIST( root="data", what="test10k" ) test_data3 = QMNIST( root="data", what="test50k", compat=False ) nist_data = QMNIST( root="data", what="nist" ) l = len l(train_data), l(test_data1), l(test_data2), l(test_data3), l(nist_data) # (60000, 60000, 10000, 50000, 402953) train_data # Dataset QMNIST # Number of datapoints: 60000 # Root location: data # Split: train train_data.root # 'data' train_data.what # 'train' train_data.compat # True train_data.train # True print(train_data.transform) # None print(train_data.target_transform) # None train_data.download # <bound method QMNIST.download of Dataset QMNIST # Number of datapoints: 60000 # Root location: data # Split: train> train_data[0] # (<PIL.Image.Image image mode=L size=28x28>, 5) test_data3[0] # (<PIL.Image.Image image mode=L size=28x28>, # tensor([3, 4, 2424, 51, 33, 261051, 0, 0])) train_data[1] # (<PIL.Image.Image image mode=L size=28x28>, 0) test_data3[1] # (<PIL.Image.Image image mode=L size=28x28>, # tensor([8, 1, 522, 60, 38, 55979, 0, 0])) train_data[2] # (<PIL.Image.Image image mode=L size=28x28>, 4) test_data3[2] # (<PIL.Image.Image image mode=L size=28x28>, # tensor([9, 4, 2496, 115, 39, 269531, 0, 0])) train_data[3] # (<PIL.Image.Image image mode=L size=28x28>, 1) test_data3[3] # (<PIL.Image.Image image mode=L size=28x28>, # tensor([5, 4, 2427, 77, 35, 261428, 0, 0])) train_data[4] # (<PIL.Image.Image image mode=L size=28x28>, 9) test_data3[4] # (<PIL.Image.Image image mode=L size=28x28>, # tensor([7, 4, 2524, 69, 37, 272828, 0, 0])) train_data.classes # ['0 - zero', '1 - one', '2 - two', '3 - three', '4 - four', # '5 - five', '6 - six', '7 - seven', '8 - eight', '9 - nine']
from torchvision.datasets import QMNIST train_data = QMNIST( root="data", what="train" ) test_data1 = QMNIST( root="data", what="test" ) test_data2 = QMNIST( root="data", what="test10k" ) test_data3 = QMNIST( root="data", what="test50k" ) nist_data = QMNIST( root="data", what="nist" ) import matplotlib.pyplot as plt def show_images(data): plt.figure(figsize=(12, 2)) col = 5 for i, (image, label) in enumerate(data, 1): plt.subplot(1, col, i) plt.title(label) plt.imshow(image) if i == col: break plt.show() show_images(data=train_data) show_images(data=test_data1) show_images(data=test_data2) show_images(data=test_data3) show_images(data=nist_data)
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!