Skip to main content
 首页 » 编程设计

python之tensorflow 初学者教程之read_data_sets 失败

2025年05月04日3552php

我正在尝试运行 tutorial在 Linux 上。我安装了gcc、cython、numpy、six。

我可以导入数据,但解包时似乎出现了某种问题。

有人可以帮忙吗?


Python 2.7.3 (default, Jun 22 2015, 19:43:34) 
[GCC 4.6.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information.    
>>> import g3doc.tutorials.mnist.input_data as input_data 
>>> mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) 
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes. 
Extracting MNIST_data/train-images-idx3-ubyte.gz 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
  File "g3doc/tutorials/mnist/input_data.py", line 175, in read_data_sets 
    train_images = extract_images(local_file) 
  File "g3doc/tutorials/mnist/input_data.py", line 60, in extract_images 
    buf = bytestream.read(rows * cols * num_images) 
  File "/usr/lib/python2.7/gzip.py", line 263, in read 
    chunk = self.extrabuf[offset: offset + size] 
TypeError: only integer scalar arrays can be converted to a scalar index 
>>> mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) 
Extracting MNIST_data/train-images-idx3-ubyte.gz 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
  File "g3doc/tutorials/mnist/input_data.py", line 175, in read_data_sets 
    train_images = extract_images(local_file) 
  File "g3doc/tutorials/mnist/input_data.py", line 60, in extract_images 
    buf = bytestream.read(rows * cols * num_images) 
  File "/usr/lib/python2.7/gzip.py", line 263, in read 
    chunk = self.extrabuf\[offset: offset + size] 
TypeError: only integer scalar arrays can be converted to a scalar index 

请您参考如下方法:

这似乎是最新版本的 Numpy 的问题。 recent change出于索引目的将单元素数组视为标量是错误的。

我已经对上游 TensorFlow 代码进行了相关更改,但与此同时您可以编辑 this line in input_data.py (L45) 如下(在行尾添加 [0]):

return numpy.frombuffer(bytestream.read(4), dtype=dt)[0]