Rumah >pembangunan bahagian belakang >Tutorial Python >EMNIST dalam PyTorch
Beli Saya Kopi☕
*Siaran saya menerangkan EMNIST.
EMNIST() boleh menggunakan set data EMNIST seperti yang ditunjukkan di bawah:
*Memo:
from torchvision.datasets import EMNIST train_data = EMNIST( root="data", split="byclass" ) train_data = EMNIST( root="data", split="byclass", train=True, transform=None, target_transform=None, download=False ) test_data = EMNIST( root="data", split="byclass", train=False ) len(train_data), len(test_data) # 697932 116323 train_data # Dataset EMNIST # Number of datapoints: 697932 # Root location: data # Split: Train train_data.root # 'data' train_data.split # 'byclass' train_data.train # True print(train_data.transform) # None print(train_data.target_transform) # None train_data.download # <bound method EMNIST.download of Dataset EMNIST # Number of datapoints: 697932 # Root location: data # Split: Train> train_data[0] # (<PIL.Image.Image image mode=L size=28x28>, 35) train_data[1] # (<PIL.Image.Image image mode=L size=28x28>, 36) train_data[2] # (<PIL.Image.Image image mode=L size=28x28>, 6) train_data[3] # (<PIL.Image.Image image mode=L size=28x28>, 3) train_data[4] # (<PIL.Image.Image image mode=L size=28x28>, 22) train_data.classes # ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', # 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', # 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', # 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', # 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
from torchvision.datasets import EMNIST train_data = EMNIST( root="data", split="byclass", train=True ) test_data = EMNIST( root="data", split="byclass", train=False ) 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_data)
from torchvision.datasets import EMNIST from torchvision.transforms import v2 train_data = EMNIST( root="data", split="byclass", train=True, transform=v2.Compose([ v2.RandomHorizontalFlip(p=1.0), v2.RandomRotation(degrees=(90, 90)) ]) ) test_data = EMNIST( root="data", split="byclass", train=False, transform=v2.Compose([ v2.RandomHorizontalFlip(p=1.0), v2.RandomRotation(degrees=(90, 90)) ]) ) 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_data)
Atas ialah kandungan terperinci EMNIST dalam PyTorch. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!