我尝试在我的计算机上运行深度MNIST教程代码(https://github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/examples/tutorials/mnist/mnist_deep.py),但在尝试打印测试准确性时会退出。我做的唯一更改是将迭代次数更改为100,并将打印频率更改为每10次迭代一次,如下所示:
第159行:
for i in range(20000):
成了
for i in range(100):
和第161行:
if i % 100 == 0:
成了
if i % 10 == 0:
这是它输出的内容(在cmd中运行):
C:\Users\Steven\Documents\Atom\tensorflow-tutorial>python -i mnist_deep.py
Extracting /tmp/tensorflow/mnist/input_data\train-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data\train-labels-idx1-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data\t10k-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data\t10k-labels-idx1-ubyte.gz
Saving graph to: C:\Users\Steven\AppData\Local\Temp\tmpeu8pfnwd
2018-01-18 21:35:00.216476: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\
36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instruct
ions that this TensorFlow binary was not compiled to use: AVX
step 0, training accuracy 0.24
step 10, training accuracy 0.16
step 20, training accuracy 0.42
step 30, training accuracy 0.64
step 40, training accuracy 0.7
step 50, training accuracy 0.68
step 60, training accuracy 0.74
step 70, training accuracy 0.74
step 80, training accuracy 0.84
step 90, training accuracy 0.78
C:\Users\Steven\Documents\Atom\tensorflow-tutorial>
请注意,一旦完成培训,即使我提供了-i标记,脚本也会自行退出而不会出现错误而不是打印测试精度。当我删除打印测试精度的行(第167和168行)时,
print('test accuracy %g' % accuracy.eval(feed_dict={
x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))
然后脚本完美无缺。因此,似乎该行导致脚本以某种方式退出。
我已尝试运行softmax教程(https://www.tensorflow.org/get_started/mnist/pros),该教程还使用相同的数据集打印测试精度,
print(accuracy.eval(feed_dict = {x: mnist.test.images, y_: mnist.test.labels}))
它运作得很好:
C:\Users\Steven\Documents\Atom\tensorflow-tutorial>python -i mnist_softmax_tutor
ial.py
Extracting MNIST_data\train-images-idx3-ubyte.gz
Extracting MNIST_data\train-labels-idx1-ubyte.gz
Extracting MNIST_data\t10k-images-idx3-ubyte.gz
Extracting MNIST_data\t10k-labels-idx1-ubyte.gz
2018-01-18 21:49:34.174464: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\
36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instruct
ions that this TensorFlow binary was not compiled to use: AVX
0.9143
>>> exit()
C:\Users\Steven\Documents\Atom\tensorflow-tutorial>
我查看了另一篇有类似错误(Deep MNIST for Experts tutorial trouble / FailedPreconditionError)的帖子,并说它运行Windows安装验证脚本(https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c)。但是,我运行它并没有遇到任何问题:
C:\Users\Steven\Documents\Atom\tensorflow-tutorial>python tensorflow_self_check.
py
TensorFlow successfully installed.
The installed version of TensorFlow does not include GPU support.
我也尝试重新安装TensorFlow(使用pip uninstall然后pip install),但这并没有解决问题。
我的python版本如下:
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
我使用
安装了tensorflowpip3 install --upgrade tensorflow
感谢任何帮助。谢谢!
答案 0 :(得分:0)
事实证明,问题是我的计算机没有足够的RAM来测试所有10000个测试图像。通常,某些东西会引发MemoryError,但我猜张量流会抑制该错误。
>>> with sess.as_default(): print(accuracy.eval(feed_dict = {x: mnist.test.image
s[:1000,:], y_: mnist.test.labels[:1000,:], keep_prob: 1.0}))
...
0.442
>>> with sess.as_default(): print(accuracy.eval(feed_dict = {x: mnist.test.image
s[:10000,:], y_: mnist.test.labels[:10000,:], keep_prob: 1.0}))
...
C:\Users\Steven\Documents\Atom\tensorflow-tutorial>
使用第二行,Python在放弃和退出之前会射出~2gb的ram。不确定为什么错误消息被抑制。
答案 1 :(得分:-1)
它在我的系统上工作,你能再次检查它吗。
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
Saving graph to: /tmp/tmpaxAoQ2
2018-01-19 17:02:14.087095: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
step 0, training accuracy 0.06
test accuracy 0.4421