python - Tensorflow CPU(在 python 交互式 shell 中正常,但运行脚本时出现 coredump)

标签 python tensorflow python-interactive

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

相关文章:

python - Tensorflow:Inception v3 批处理

从 stdin 读取时,python 交互模式不起作用

python - 等同于普通 python 中的 Ipython 运行命令

python - 在 Pycharm : How to turn off interactive mode? 中调试时使用 Matplotlib

python - 无法从网页的不同深度抓取相似的链接

python - dataframe.to_hdf() 中的参数键是什么意思

python - PySphere 和 PyVmomi 有什么区别?

tensorflow - 什么是具有强度 1 边缘矩阵的设备互连 StreamExecutor

python - 加载CKAN数据集

tensorflow - 如何在基于 Keras 的 LSTM 模型的每个时期获得一层的权重矩阵?