tensorflow.python.framework.errors_impl.InternalError:使用wide_n_deep_tutorial.py时无法从feed中获取元素作为字节

时间:2017-08-31 05:42:04

标签: python tensorflow

当我尝试使用tensorflow官方网站提供的wide_n_deep_tutorial.py时,该教程可以成功运行,但在我更改数据和相应功能后,它将显示以下错误:

File "wide_n_deep_feed.py", line 224, in <module>
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "/usr/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "wide_n_deep_feed.py", line 185, in main
    FLAGS.train_data, FLAGS.test_data)
  File "wide_n_deep_feed.py", line 166, in train_and_eval
    steps=train_steps)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 241, in train
    loss = self._train_model(input_fn=input_fn, hooks=hooks)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 686, in _train_model
    _, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss])
  File "/usr/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 534, in __exit__
    self._close_internal(exception_type)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 569, in _close_internal
    self._sess.close()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 811, in close
    self._sess.close()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 908, in close
    ignore_live_threads=True)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/training/coordinator.py", line 389, in join
    six.reraise(*self._exc_info_to_raise)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/inputs/queues/feeding_queue_runner.py", line 94, in _run
    sess.run(enqueue_op, feed_dict=feed_dict)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 895, in run
    run_metadata_ptr)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1124, in _run
    feed_dict_tensor, options, run_metadata)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
    options, run_metadata)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InternalError: Unable to get element from the feed as bytes.

PS:我的models目录中已经生成了一些文件: checkpoint,events,graph.pbtxt,model.ckpt-0.data-00000-of-00001,model.ckpt-0.index,model.ckpt-0.meta

任何答案都将不胜感激。

1 个答案:

答案 0 :(得分:3)

编辑:

当您使用具有NaN值的数据框时发生错误,因此Tensorflow无法将列转换为tf.Dtype,您可以使用示例代码中的行:

df_data = df_data.dropna(how="any", axis=0)

删除所有NaN样本,或者您可以强制转换数字列并将所有NaN值替换为空字符串,如下所示:

# Cast to numeric column
df_data["numeric_column_title"] = pd.to_numeric(df_data["numeric_column_title"],errors='coerce')
# Replace NaN value with 0
df_data[["numeric_column_title1", "numeric_column_title2"]] = df_data[["numeric_column_title1", "numeric_column_title2"]].fillna(value=0)
# Replace other string columns with empty string
df_data = df_data.fillna(value='')

希望这有帮助:)