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 中?


基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01