TensorFlow实战调试中所遇问题及解决方法1

程序源码(节选):

exampleBatch1, labelBatch1 = batch_input(dataPath, num_epochs=100)

with tf.Session() as sess:
    init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
    sess.run(init_op)

    #exampleBatch1, labelBatch1 = batch_input(dataPath, num_epochs=100)
    coord = tf.train.Coordinator()

    threads = tf.train.start_queue_runners(sess=sess, coord=coord)

    try:
        while not coord.should_stop():
            example_batch, label_batch = sess.run([exampleBatch1, labelBatch1])
            print("example_batch is:")
            print(example_batch)
    except tf.errors.OutOfRangeError:  
        print('Done training -- epoch limit reached') 
    finally:
        coord.request_stop()

        coord.join(threads)


运行时报以下错误:

Traceback (most recent call last):
  File "better_nonlinear_one_input_batch1.py", line 64, in <module>
    coord.join(threads)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/coordinator.py", line 389, in join
    six.reraise(*self._exc_info_to_raise)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/queue_runner_impl.py", line 238, in _run
    enqueue_callable()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1231, in _single_operation_run
    target_list_as_strings, status, None)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Field 7 in record 0 is not a valid int32: 12/19/2017 10:40:43

[[Node: DecodeCSV = DecodeCSV[OUT_TYPE=[DT_STRING, DT_STRING, DT_STRING, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT32, DT_STRING, DT_INT32, DT_STRING, DT_STRING], field_delim=",", na_value="", use_quote_delim=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ReaderReadV2:1, DecodeCSV/record_defaults_0, DecodeCSV/record_defaults_1, DecodeCSV/record_defaults_0, DecodeCSV/record_defaults_3, DecodeCSV/record_defaults_3, DecodeCSV/record_defaults_3, DecodeCSV/record_defaults_3, DecodeCSV/record_defaults_7, DecodeCSV/record_defaults_0, DecodeCSV/record_defaults_7, DecodeCSV/record_defaults_1, DecodeCSV/record_defaults_0)]]


经过仔细检查,csv数据中有1行,其中的一列数据出现错误(第7列):

北京市    北京南站 创新工场 39.8710745104 116.3861028586 39.9904135156 116.3217241961 22634 多云 2850 周二 12/19/2017 10:40:40
北京市    北京南站 险峰华兴 39.8710745104 116.3861028586 39.9298750516 116.4177599721 12/19/2017 10:40:43 多云 2489 周二 12/19/2017 10:40:40
北京市 北京南站 经纬中国 39.8710745104 116.3861028586 39.9299857781 116.3956450379 10860 多云 2631 周二 12/19/2017 10:40:41

本应该是距离的数值(整型),此处变成了日期值,类型错误,修正后程序可正常运行。


发布了34 篇原创文章 · 获赞 12 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/phmatthaus/article/details/79377006
今日推荐