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

解决TensorFlow中因CSV数据格式不正确导致的程序错误,详细分析了错误原因并给出了具体的修正措施。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

程序源码(节选):

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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝天居士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值