【问题标题】:Tensorflow: Reading MNIST Data in Python 3.5Tensorflow:在 Python 3.5 中读取 MNIST 数据
【发布时间】:2017-07-12 14:51:45
【问题描述】:

我刚刚开始使用 ML 和 Tensorflow。在(我认为)在我的 ubuntu 系统上成功安装了 tensorflow 之后。我想用 tensorflow 为手写的 digits 实现一个 CNN。如果在stackoverflow中阅读了几个问题并且在没有任何解决方案的情况下愚弄了2天。

    import tensorflow as tf
    import matplotlib.pyplot as plt
    import struct
    import numpy as np
    from mpl_toolkits.mplot3d import Axes3D

    from tensorflow.examples.tutorials.mnist import input_data
    data = input_data.read_data_sets("./MNIST/", one_hot=True)

    mnist = MNIST("./data/")   

    # for now i just wanna print something that tells me i successfully   
    # read the data
    print("Size of:")
    print("- Training-set:\t\t{}".format(len(data.train.labels)))
    print("- Test-set:\t\t{}".format(len(data.test.labels)))
    print("- Validation-set:\t{}".format(len(data.validation.labels)))

我得到的是:

    ---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
<ipython-input-3-17f8ae55d032> in <module>()
      7 
      8 # Import MNIST data
----> 9 from tensorflow.examples.tutorials.mnist import input_data
     10 data = input_data.read_data_sets("./MNIST/", one_hot=True)
     11 

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/examples/tutorials/mnist/__init__.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from tensorflow.examples.tutorials.mnist import input_data
     22 from tensorflow.examples.tutorials.mnist import mnist

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/examples/tutorials/mnist/input_data.py in <module>()
     27 from six.moves import xrange  # pylint: disable=redefined-builtin
     28 import tensorflow as tf
---> 29 from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/__init__.py in <module>()
     23 from tensorflow.contrib import copy_graph
     24 from tensorflow.contrib import crf
---> 25 from tensorflow.contrib import cudnn_rnn
     26 from tensorflow.contrib import distributions
     27 from tensorflow.contrib import factorization

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/cudnn_rnn/__init__.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops import CudnnGRU
     22 from tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops import CudnnLSTM
     23 from tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops import CudnnRNNRelu

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py in <module>()
     26 
     27 _cudnn_rnn_ops_so = loader.load_op_library(
---> 28     resource_loader.get_path_to_datafile("_cudnn_rnn_ops.so"))
     29 
     30 _cudnn_rnn_common_doc_string = """

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/util/loader.py in load_op_library(path)
     40   if os.name != 'nt':
     41     path = resource_loader.get_path_to_datafile(path)
---> 42     ret = load_library.load_op_library(path)
     43     assert ret, 'Could not load %s' % path
     44     return ret

/home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/load_library.py in load_op_library(library_filename)
     62       # pylint: disable=protected-access
     63       raise errors_impl._make_specific_exception(
---> 64           None, None, error_msg, error_code)
     65       # pylint: enable=protected-access
     66   finally:

NotFoundError: /home/vanmunky/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/cudnn_rnn/python/ops/_cudnn_rnn_ops.so: cannot open shared object file: No such file or directory

我几乎可以肯定 4 gz 文件在错误的位置,但我几乎把它们放在任何地方。那么根据这段代码,我到底要把数据放在哪里?还是代码错了?我错过了什么?

谢谢

【问题讨论】:

    标签: python tensorflow neural-network mnist


    【解决方案1】:

    堆栈跟踪的问题不在于 mnist 数据集的路径。您已安装 tensorflow with GPU 支持,但它无法链接到所需的 cudnn 库。如果你真的想在 gpu 上使用 tensorflow,请确保你拥有所有 GPU requirements。否则你只需要重新安装tensorflow with CPU(假设你使用anaconda)。

    【讨论】:

    • 我认为可能有问题,但我安装了 CPU 版本(是的,使用 anaconda)。所以这听起来可能微不足道,但我必须在哪条路径下删除数据?!
    猜你喜欢
    • 2019-09-07
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2017-12-09
    • 1970-01-01
    • 2020-06-03
    相关资源
    最近更新 更多