Home >Backend Development >Python Tutorial >KMNIST in PyTorch
Buy Me a Coffee☕
*My post explains KMNIST.
KMNIST() can use KMNIST dataset as shown below:
*Memos:
from torchvision.datasets import KMNIST train_data = KMNIST( root="data" ) train_data = KMNIST( root="data", train=True, transform=None, target_transform=None, download=False ) test_data = KMNIST( root="data", train=False ) len(train_data), len(test_data) # (60000, 10000) train_data # Dataset KMNIST # Number of datapoints: 60000 # Root location: data # Split: Train train_data.root # 'data' train_data.train # True print(train_data.transform) # None print(train_data.target_transform) # None train_data.download # <bound method MNIST.download of Dataset KMNIST # Number of datapoints: 60000 # Root location: data # Split: Train> train_data[0] # (<PIL.Image.Image image mode=L size=28x28>, 8) train_data[1] # (<PIL.Image.Image image mode=L size=28x28>, 7) train_data[2] # (<PIL.Image.Image image mode=L size=28x28>, 0) train_data[3] # (<PIL.Image.Image image mode=L size=28x28>, 1) train_data[4] # (<PIL.Image.Image image mode=L size=28x28>, 4) train_data.classes # ['o', 'ki', 'su', 'tsu', 'na', 'ha', 'ma', 'ya', 're', 'wo']
from torchvision.datasets import KMNIST train_data = KMNIST( root="data", train=True ) test_data = KMNIST( root="data", 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)
The above is the detailed content of KMNIST in PyTorch. For more information, please follow other related articles on the PHP Chinese website!