tensorflow教程中的“utf8”解码错误

2024-06-02 05:58:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个奇怪的问题

  from tensorflow.examples.tutorials.mnist import input_data

  mnist = input_data.read_data_sets('/home/fqiao/development/MNIST_data/', one_hot=True)

我得到:

^{pr2}$

但是,如果我只是在输入中运行代码_数据.py很明显,一切似乎都很好:

>>> dt = numpy.dtype(numpy.uint32).newbyteorder('>')
>>> f = tf.gfile.Open('/home/fqiao/development/MNIST_data/train-images-idx3-ubyte.gz', 'rb')
>>> bytestream = gzip.GzipFile(fileobj=f)
>>> testbytes = numpy.frombuffer(bytestream.read(4), dtype=dt)[0]
>>> testbytes
2051

有人知道发生了什么吗?在

我的Ubuntux64.5.5系统。在


Tags: fromnumpyhomereadinputdatatensorflowdt
2条回答

在我的例子中,问题在于数据文件的编码。在

使用vim打开文件并执行:

:set fileencoding=utf-8

这就解决了我的问题。在

最近的一个变更555e73d已经解决了这个bug。MNIST文件需要以二进制'rb'模式打开,而不仅仅是文本'r'。在

相关问题 更多 >