最近在跑github上的一个DCGAN(Deep Convolutional Generative Adversarial Networks)项目(项目代码路径:https://github.com/carpedm20/DCGAN-tensorflow)时,遇到了下面的问题:
2018-12-17 22:46:22.845004: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "main.py", line 97, in
tf.app.run()
File "D:\software_installed\Anaconda\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "main.py", line 61, in main
sample_dir=FLAGS.sample_dir)
File "D:\ML\jupyter\github\21DeepLearningProjects\21DeepLearningProjects\Ch8_Gan\model.py", line 74, in __init__
self.data_X, self.data_y = self.load_mnist()
File "D:\ML\jupyter\github\21DeepLearningProjects\21DeepLearningProjects\Ch8_Gan\model.py", line 464, in load_mnist
fd = open(os.path.join(data_dir, 'train-images-idx3-ubyte'))
PermissionError: [Errno 13] Permission denied: './data\\mnist\\train-images-idx3-ubyte'
这是一个用对抗神经网络生成手写字体的实例,从日志中可以看出原因是读取data/mnist/train-images-idx3-ubyte时Permission denied了。train-images-idx3-ubyte是mnist数据集中的一个文件。
因为代码是GitHub上的,所以原始代码应该没有问题才对。在网上找了一圈,在https://blog.csdn.net/qq_41185868/article/details/82913883链接中看到了问题原因,所以在此记录一下,也感谢这位大神的帮助。
问题原因:我使用的Windows系统,而在Windows下,访问一个文件是要带后缀名的。我将train-images-idx3-ubyte改为train-images.idx3- ubyte后问题得到解决。model.py里load_mnist方法中相对应的加载其他几个文件的代码也需要,修改后代码如下:
def load_mnist(self):
data_dir = os.path.join("./data", self.dataset_name)
print("data_dir=", data_dir)
#use in linux
#fd = open(os.path.join(data_dir, 'train-images-idx3-ubyte'))
#use in windows
fd = open(os.path.join(data_dir, 'train-images.idx3-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
trX = loaded[16:].reshape((60000,28,28,1)).astype(np.float)
#fd = open(os.path.join(data_dir,'train-labels-idx1-ubyte'))
fd = open(os.path.join(data_dir, 'train-labels.idx1-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
trY = loaded[8:].reshape((60000)).astype(np.float)
#fd = open(os.path.join(data_dir, 't10k-images-idx3-ubyte'))
fd = open(os.path.join(data_dir, 't10k-images.idx3-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
teX = loaded[16:].reshape((10000,28,28,1)).astype(np.float)
#fd = open(os.path.join(data_dir,'t10k-labels-idx1-ubyte'))
fd = open(os.path.join(data_dir, 't10k-labels.idx1-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
teY = loaded[8:].reshape((10000)).astype(np.float)