explains can use EMNIST dataset as shown below:
*Memos:
- The 1st argument is
root(Required-Type:strorpathlib.Path). *An absolute or relative path is possible. - The 2nd argument is
split(Required-Type:str). *"byclass","bymerge","balanced","letters","digits"or"mnist"can be set to it. - There is
trainargument(Optional-Default:False-Type:float):
*Memos:
- For
split="byclass"andsplit="byclass", if it'sTrue, train data(697,932 images) is used while if it'sFalse, test data(116,323 images) is used. - For
split="balanced", if it'sTrue, train data(112,800 images) is used while if it'sFalse, test data(188,00 images) is used. - For
split="letters", if it'sTrue, train data(124,800 images) is used while if it'sFalse, test data(20,800 images) is used. - For
split="digits", if it'sTrue, train data(240,000 images) is used while if it'sFalse, test data(40,000 images) is used. - For
split="mnist", if it'sTrue, train data(60,000 images) is used while if it'sFalse, test data(10,000 images) is used.
- For
- There is
transformargument(Optional-Default:None-Type:callable). - There is
target_transformargument(Optional-Default:None-Type:callable). - There is
downloadargument(Optional-Default:False-Type:bool):
*Memos:
- If it's
True, the dataset is downloaded from the internet and extracted(unzipped) toroot. - If it's
Trueand the dataset is already downloaded, it's extracted. - If it's
Trueand the dataset is already downloaded and extracted, nothing happens. - It should be
Falseif the dataset is already downloaded and extracted because it's faster. - You can manually download and extract the dataset from
CODEfrom 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)
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
- If it's

SOCIAL SHARE CARD GENERATOR