我正在Windows上使用python 3.5和tensorflow。我写了一个脚本,从idx文件中获取MNIST数据,它工作正常。我能够打开单个图像。今天我打开我的项目,现在遇到以下问题:
File "C:\Users\uidj8441\Documents\PYTHON\0_projects\open MNIST data\open_mnist
_data\open_mnist_data\open_mnist_data.py", line 27, in <module>
images, labels = mnist.load_training() #training set
AttributeError: 'Datasets' object has no attribute 'load_training'
我不知道这个问题是从哪里来的。请参阅下面的完整代码:
#### libaries
import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import time
import tensorflow as tf
from mnist import MNIST
import random
from PIL import Image, ImageOps
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #deactivate warnings
#### set and print working folder
os.chdir('C:\\Users\\uidj8441\\Documents\\PYTHON\\0_projects\\open MNIST data\\open_mnist_data\\open_mnist_data')
print('working folder:\n\n',os.getcwd(),'\n')
#### load dataset (training or test)
## a) offline-download: from idx1 / idx3 files
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('C:\\Users\\uidj8441\\Documents\\PYTHON\\0_projects\\open MNIST data\\open_mnist_data\\open_mnist_data\\',one_hot=True)
## b) online-download via (firewall might be blocking)
#from tensorflow.examples.tutorials.mnist import input_data
#mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
images, labels = mnist.load_training() #training set
#images, labels = mnist.load_testing() #test set
#### display random image
print('\nLoading random image and display\n')
index=random.randrange(0,len(images))
print('Random image with index',index,'is a:',labels[index])
print(mnist.display(images[index]))
#### display explicit image
img_num=8
print('\n Chosen image with index',img_num, 'is a:',labels[img_num])
print(mnist.display(images[img_num]))
最佳答案
你的命令
mnist = input_data.read_data_sets('C:\\Users\\uidj8441\\Documents\\PYTHON\\0_projects\\open MNIST data\\open_mnist_data\\open_mnist_data\\',one_hot=True)
...从Google服务器下载
MNIST
数据集,将压缩文件放入文件夹C:\\Users\\uidj8441\\Documents\\PYTHON\\0_projects\\open MNIST data\\open_mnist_data\\open_mnist_data\\
并将目标编码为one_hot
。现在,您可以访问3个数据集,即
train
,test
,validation
。例如。在训练阶段,您的命令将以
mnist.train.{something}
开头,而不是上面代码中的mnist.{something}
。关于python - 加载数据集时,MNIST属性错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44108114/