本文介绍了pytorch 把MNIST数据集转换成图片和txt的方法,分享给大家,具体如下:
1.下载Mnist 数据集
import os
# third-party library
import torch
import torch.nn as nn
from torch.autograd import Variable
import torch.utils.data as Data
import torchvision
import matplotlib.pyplot as plt
# torch.manual_seed(1) # reproducible
DOWNLOAD_MNIST = False
# Mnist digits dataset
if not(os.path.exists('./mnist/')) or not os.listdir('./mnist/'):
# not mnist dir or mnist is empyt dir
DOWNLOAD_MNIST = True
train_data = torchvision.datasets.MNIST(
root='./mnist/',
train=True, # this is training data
transform=torchvision.transforms.ToTensor(), # Converts a PIL.Image or numpy.ndarray to
# torch.FloatTensor of shape (C x H x W) and normalize in the range [0.0, 1.0]
download=DOWNLOAD_MNIST,
)
下载下来的其实可以直接用了,但是我们这边想把它们转换成图片和txt,这样好看些,为后面用自己的图片和txt作为准备
- 保存为图片和txt
import os
from skimage import

本文提供PyTorch将MNIST数据集转换为图片和TXT文件的教程。通过该过程,可以更直观地查看数据,并为自定义训练集创建准备。内容包括数据下载及转换步骤,同时推荐了一个Python学习资源。
最低0.47元/天 解锁文章
899

被折叠的 条评论
为什么被折叠?



