我正在尝试在单CPU模式下学习Tensorflow。当我尝试运行一些示例时,例如 [mnist_softmax.py]
,似乎整个代码运行正确并输出预期的答案,但显示 [Segmentation failure (core dumped)]
最终生成1.7G甚至更大的core文件。
当我在 python 交互式 shell 中运行相同的代码时,它运行良好,不会出现这样的段错误。
我的 Tensorflow
版本是 ('v1.0.0-65-g4763edf-dirty', '1.0.1')
最佳答案
将第 61 行从 sess = tf.InteractiveSession()
更改为
至sess = tf.Session()
并在命令行上重新运行它。
用此替换第 61 至 72 行
with tf.Session() as sess:
tf.global_variables_initializer().run()
# Train
for _ in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
# Test trained model
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images,
y_: mnist.test.labels}))
关于python - Tensorflow CPU(在 python 交互式 shell 中正常,但运行脚本时出现 coredump),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43864427/