1

I'm trying to learn Tensorflow on Single CPU mode. When I try to run some examples , such as [mnist_softmax.py] it seems that the whole code run correctly and output the expected answer, but shows [Segmentation fault (core dumped)] and generate a 1.7G or even bigger core file in the end. When I run the same code in python interactive shell, it runs well and won't appear such Segmentation fault.

And my Tensorflow version is ('v1.0.0-65-g4763edf-dirty', '1.0.1')

Aditya
  • 2,380
  • 2
  • 14
  • 39
AcAhe
  • 13
  • 2
  • a look at the code might help others to answer – Aditya May 09 '17 at 08:13
  • https://github.com/tensorflow/tensorflow/blob/r1.1/tensorflow/examples/tutorials/mnist/mnist_softmax.py – AcAhe May 09 '17 at 08:15
  • It's the example on the tensorflow.org [MNIST For ML Beginners]. – AcAhe May 09 '17 at 08:16
  • I don't know if this problem correlates with sess = tf.InteractiveSession(), but after I comment the script from here to the end, there'll be no core dump. – AcAhe May 09 '17 at 08:26

1 Answers1

1

Change line 61 from sess = tf.InteractiveSession() to sess = tf.Session() and rerun it on the command line.

replace from line 61 to 72 with this

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}))
Anton Codes
  • 3,663
  • 1
  • 19
  • 28
  • The command line script is not an interactive session, and therein lies your problem. – Anton Codes May 09 '17 at 13:51
  • it hints that [ValueError: Cannot execute operation using `run()`: No default session is registered. Use `with sess.as_default():` or pass an explicit session to `run(session=sess)]'if I change InteractiveSession() to Session directly – AcAhe May 10 '17 at 03:12
  • And I try to use [with tf.Session() as sess:] instead of InteractiveSession() to cover the last code. But it still gives me Segmentation fault at the end. – AcAhe May 10 '17 at 03:15
  • @AcAhe I'm not sure what change you've made specifically. I have though updated the solution I posted with the exact change I am recomending. If this doesn't work can you send a link to the full code that you tried that includes my changes? – Anton Codes May 10 '17 at 13:21
  • the code link is above. and here's the output after I run this code. https://github.com/acahesky/4Debug/blob/master/output.txt – AcAhe May 11 '17 at 08:03
  • I'm running tensorflow version 1.0.1 also. I downloaded your code and ran it locally and it exited fine. Interestingly I did get all the warnings and output you got **other than** *W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.* – Anton Codes May 11 '17 at 14:47
  • Here is a link to a help page that describes how to address the SSE3 instructions : https://github.com/tensorflow/tensorflow/issues/7693 – Anton Codes May 11 '17 at 14:50
  • @AcAhe if this answers your original question then please mark this as the accepted answer. – Anton Codes Jun 01 '17 at 15:46