1

我正在尝试在单 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')

4

1 回答 1

1

将第 61 行从sess = tf.InteractiveSession() to更改为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}))
于 2017-05-09T13:44:42.753 回答