我在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]))
答案 0 :(得分:1)
你的命令......
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
。
E.g。在火车阶段,您的命令将从mnist.train.{something}
开始,而不是您在上面的代码中执行的mnist.{something}
。