python MNIST 数据集 "no attribute train_images"

python MNIST dataset "no attribute train_images"

我正在使用 python3.7 并尝试使用 MNIST 训练数据图像。 我尝试直接使用 mnist 模块,而不是使用 PyTorch、tf、kears framwork 来帮助轻松使用数据集。

我正在关注 CNN a tutorial

import mnist

然后我尝试"pip install python-mnist"(卸载python-mnist后,我已经完成了'pip install mnist')并成功下载。 然后我输入相同的代码来制作火车图像。

train_images = mnist.train_images()

然而它说 "AttributeError: module 'mnist' has no attribute 'train_images'"

我检查了 print(mnist),它给出了路径, 但是 print(mnist.train_images) 给出了相同的错误信息。 据我所知,可以在'init.py'中使用函数,但它似乎并没有......或者我错了什么?

enter image description here

++ 此外,即使我删除了 mnist 文件夹和 运行 相同的代码,它仍然存在打印出相同的路径,我相信它应该打印 'there is no module mnist' ..什么我现在缺少某种知识..? :(

提前谢谢你,

实际上,您只需按照 MNIST (link) Github 页面上的说明进行操作即可。 使用 pip install python-mnist 安装 lib 后,您应该克隆 repo 并执行脚本来下载 mnist 数据:

git clone https://github.com/sorki/python-mnist
cd python-mnist
./get_data.sh

您的数据将保存在名为 data 的文件夹中,之后您可以在代码中调用它:

from mnist import MNIST
mndata = MNIST('data/')
mndata.gz = False
images, labels = mndata.load_training()

images 变量是像素列表的列表,您应该在之后对其进行整形以查看图像。

注意:如果我是你,我会只使用 pytorchKeras,因为它们更容易,它们会为你完成工作。之后,如果你不想使用张量,你可以将它们转换回 numpy 数组。

Also note if you have a file ./mnist.py in your local folder, then this will take over and prevent you from importing the desired mnist library.

就用 \\\
\\\\

from mnist import *

x_train=train_images()

y_train=train_labels()