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 中?
基础教程推荐
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
