简体   繁体   English

Tensorflow:在Python 3.5中读取MNIST数据

[英]Tensorflow: Reading MNIST Data in Python 3.5

im just getting started with ML and Tensorflow. 我刚刚开始使用ML和Tensorflow。 After having (i think) successfully installed tensorflow on my ubuntu system. (我认为)在我的ubuntu系统上成功安装了tensorflow之后。 I wanted to implement a CNN with tensorflow for handwritten didgits. 我想为手写的didgits实现一个带有tensorflow的CNN。 If have read through a couple of questions in stackoverflow and fooled around 2 days without any solution. 如果已经阅读了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)))

What i get out is: 我得到的是:

    ---------------------------------------------------------------------------
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

Im almost certain that the 4 gz files are at the wrong place, but I put them almost everywhere. 我几乎可以确定4 gz文件在错误的位置,但是我几乎将它们放在任何地方。 So according to this code where exactly do I have to put the data? 因此,根据此代码,我到底要将数据放在哪里? Or is the code wrong? 还是代码错误? What do I miss? 我想念什么?

Thanks 谢谢

The problem from a stacktrace is not in with a path to mnist dataset. stacktrace的问题不在mnist数据集的路径中。 You've installed tensorflow with GPU support, but it cannot link to required cudnn library. 您已经安装了具有GPU支持的tensorflow ,但是它无法链接到所需的cudnn库。 If you really want to use tensorflow with gpu, make sure you have all GPU requirements . 如果您确实想将tensorflow与gpu一起使用,请确保满足所有GPU要求 Otherwise you just need to reinstall tensorflow with CPU (assuming you use anaconda). 否则,您只需要使用CPU重新安装tensorflow (假设您使用anaconda)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM