Tensorflow CPU(在 python 交互式 shell 中正常,但在 运行 脚本时出现核心转储)

Tensorflow CPU (normal in python interactive shell, but coredump when run script)

我正在尝试在单一 CPU 模式下学习 Tensorflow。当我尝试 运行 一些示例时,例如 [mnist_softmax.py] 似乎整个代码 运行 正确并输出预期的答案,但显示 [Segmentation fault (core dumped)] 并生成 1.7G 或最后甚至更大的核心文件。 当我运行在python交互式shell中使用相同的代码时,它运行很好,不会出现这样的Segmentation fault.

我的 Tensorflow 版本是 ('v1.0.0-65-g4763edf-dirty', '1.0.1')

sess = tf.InteractiveSession() 更改第 61 行 至 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}))