TensorFlow使用next_batch()读取/tensorflow.python.framework.errors_impl.InvalidArgumentError: Expect 3 fi
来源:互联网 发布:白银模拟交易软件 编辑:程序博客网 时间:2024/05/18 02:37
分批次读取数据
数据模板:
源代码
-------------------------------------------------
import tensorflow as tfimport numpy as npdef readMyFileFormat(fileNameQueue): reader = tf.TextLineReader() key, value = reader.read(fileNameQueue) record_defaults = [[1.0], [1.0], [1.0]] x1, x2, x3 = tf.decode_csv(value, record_defaults=record_defaults) features = tf.stack([x1, x2]) label = x3 return features, labeldef inputPipeLine(fileNames=["Test.csv"], batchSize = 4, numEpochs = None): fileNameQueue = tf.train.string_input_producer(fileNames, num_epochs = numEpochs) example, label = readMyFileFormat(fileNameQueue) min_after_dequeue = 8 capacity = min_after_dequeue + 3 * batchSize exampleBatch, labelBatch = tf.train.shuffle_batch([example, label], batch_size=batchSize, num_threads=3, capacity=capacity, min_after_dequeue=min_after_dequeue) return exampleBatch, labelBatchfeatureBatch, labelBatch = inputPipeLine(["Test.csv"], batchSize=4)with tf.Session() as sess: # Start populating the filename queue. coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) example, label = sess.run([featureBatch, labelBatch]) print(example, label) coord.request_stop() coord.join(threads) sess.close()
----------------------------------------------------------------------------------------------------------------------------------------------------
出现错误:
C:/Users/User/PycharmProjects/Test/test.py
2017-09-25 15:04:46.598434: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-09-25 15:04:46.598711: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-25 15:04:46.598974: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\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.
2017-09-25 15:04:46.599224: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-25 15:04:46.599460: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-25 15:04:46.599708: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-09-25 15:04:46.599948: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-25 15:04:46.600168: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
[[ 7. 8.]
[ 2. 4.]
[ 1. 2.]
[ 1. 2.]] [ 11. 42. 10. 10.]
Traceback (most recent call last):
File "C:/Users/JZ/PycharmProjects/Test/test.py", line 30, in <module>
coord.join(threads)
File "C:\Users\JZ\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\coordinator.py", line 389, in join
six.reraise(*self._exc_info_to_raise)
File "C:\Users\JZ\AppData\Local\Programs\Python\Python35\lib\site-packages\six.py", line 686, in reraise
raise value
File "C:\Users\JZ\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\queue_runner_impl.py", line 238, in _run
enqueue_callable()
File "C:\Users\JZ\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1063, in _single_operation_run
target_list_as_strings, status, None)
File "C:\Users\JZ\AppData\Local\Programs\Python\Python35\lib\contextlib.py", line 66, in __exit__
next(self.gen)
File "C:\Users\JZ\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Expect 3 fields but have 0 in record 0
[[Node: DecodeCSV = DecodeCSV[OUT_TYPE=[DT_FLOAT, DT_FLOAT, DT_FLOAT], field_delim=",", _device="/job:localhost/replica:0/task:0/cpu:0"](ReaderReadV2:1, DecodeCSV/record_defaults_0, DecodeCSV/record_defaults_1, DecodeCSV/record_defaults_2)]]
错误原因:很可能是CSV文件数据最后还有多余的行,例如我出现的原因
Similarly, you might want to check out your data file to see if there is any wrong with it, even if it is as trivial as "a blank line".
参考资料:
https://stackoverflow.com/questions/43781143/tensorflow-decode-csv-expect-3-fields-but-have-5-in-record-0-when-given-5-de
http://blog.csdn.net/yiqingyang2012/article/details/68485382
http://wiki.jikexueyuan.com/project/tensorflow-zh/how_tos/reading_data.html
tensorflow官方文档
- TensorFlow使用next_batch()读取/tensorflow.python.framework.errors_impl.InvalidArgumentError: Expect 3 fi
- tensowflow报错tensorflow.python.framework.errors_impl.InvalidArgumentError<exception str
- Tensorflow报错tensorflow.python.framework.errors_impl.InvalidArgumentError exception str() failed原因
- tensorflow bug: tensorflow.python.framework.errors_impl.NotFoundError
- tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized val
- Tensorflow数据读取有三种方式(next_batch)
- TensorFlow restore模型时报错tensorflow.python.framework.errors_impl.NonArgumentError exception str()
- tensorflow中next_batch
- tensorflow.python.framework.errors.InvalidArgumentError: Input to reshape is a tensor with xxx value
- 报tensorflow.python.framework.errors.InvalidArgumentError:Node'save/restore_slice_2':错误的解决方案
- 【Ubuntu-Tensorflow】InvalidArgumentError GPU不能使用的问题
- tensorflow(6) mnist.train.next_batch()函数解析
- tensorflow做交叉验证遇到InvalidArgumentError
- Tensorflow InvalidArgumentError Invalid JPEG data, size xxxx
- SSD Tensorflow:InvalidArgumentError: about bounding box coordinates
- 使用python读取tensorflow实例中的MNIST模拟数据
- TensorFlow:Windows下使用TensorFlow-Python版本
- TensorFlow报错InvalidArgumentError (see above for traceback)
- 网页布局方式
- bzoj 3386: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
- Altium Designer多通道设计原理图添加端口
- js中SetInterval与setTimeout用法
- 16. 入口脚本
- TensorFlow使用next_batch()读取/tensorflow.python.framework.errors_impl.InvalidArgumentError: Expect 3 fi
- jupyter noteboook 的 markdown语法
- HDU3037Saving Beans(lucas定理模板)
- R语言树模型
- SpringBoot学习-mybatis逆向生成工具
- 转换说明符
- maven中的groupId和artifactId到底指的是什么?
- java--遇到NoSuchMethodError通用解决思路
- 头条号《群媒体》,自媒体工作室必看