How do you load MNIST images into Pytorch DataLoader?(如何将 MNIST 图像加载到 Pytorch DataLoader 中?)
问题描述
用于数据加载和处理的 pytorch 教程非常具体到一个示例,有人可以帮助我了解更通用的简单图像加载的函数应该是什么样的吗?
The pytorch tutorial for data loading and processing is quite specific to one example, could someone help me with what the function should look like for a more generic simple loading of images?
教程:http://pytorch.org/tutorials/beginner/data_loading_tutorial.html
我的数据:
我在以下文件夹结构中有 MINST 数据集作为 jpg.(我知道我可以只使用数据集类,但这纯粹是为了看看如何将简单的图像加载到 pytorch 中,而没有 csv 或复杂的特征).
I have the MINST dataset as jpg's in the following folder structure. (I know I can just use the dataset class, but this is purely to see how to load simple images into pytorch without csv's or complex features).
文件夹名称是标签,图像是 28x28 的灰度 png,无需转换.
The folder name is the label and the images are 28x28 png's in greyscale, no transformations required.
data
train
0
3.png
5.png
13.png
23.png
...
1
3.png
10.png
11.png
...
2
4.png
13.png
...
3
8.png
...
4
...
5
...
6
...
7
...
8
...
9
...
推荐答案
这是我为 pytorch 0.4.1 所做的(应该仍然适用于 1.3)
Here's what I did for pytorch 0.4.1 (should still work in 1.3)
def load_dataset():
data_path = 'data/train/'
train_dataset = torchvision.datasets.ImageFolder(
root=data_path,
transform=torchvision.transforms.ToTensor()
)
train_loader = torch.utils.data.DataLoader(
train_dataset,
batch_size=64,
num_workers=0,
shuffle=True
)
return train_loader
for batch_idx, (data, target) in enumerate(load_dataset()):
#train network
这篇关于如何将 MNIST 图像加载到 Pytorch DataLoader 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 MNIST 图像加载到 Pytorch DataLoader 中?
基础教程推荐
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
