解决PermissionError: [Errno 13] Permission denied: './data\\mnist\\train-images-idx3-ubyte'

1.问题描述

 最近在跑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 <module>
    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数据集中的一个文件。

2.解决办法 

因为代码是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)

 

  • 9
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值