请我喝杯咖啡☕
*我的帖子解释了 mnist。
mnist() 可以使用 mnist 数据集,如下所示:
*备忘录:
from torchvision.datasets import mnist
train_data = mnist(
root="data"
)
train_data = mnist(
root="data",
train=true,
transform=none,
target_transform=none,
download=false
)
train_data
# dataset mnist
# 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 mnist
# number of datapoints: 60000
# root location: data
# split: train>
train_data[0]
# (<pil.image.image image mode=l size=28x28>, 5)
train_data[1]
# (<pil.image.image image mode=l size=28x28>, 0)
train_data[2]
# (<pil.image.image image mode=l size=28x28>, 4)
train_data[3]
# (<pil.image.image image mode=l size=28x28>, 1)
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 MNIST
train_data = MNIST(
root="data"
)
test_data = MNIST(
root="data",
train=False
)
import matplotlib.pyplot as plt
def show_images(data):
plt.figure(figsize=(10, 2))
col = 4
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)

以上就是PyTorch 中的 MNIST的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号