我想导入各种类型的列,如 int、float、string 作为张量。只有第一个 record_defaults 工作,其中所有设置为字符串。
但我得到下面的错误。有没有办法将 tensorflow 与各种类型的占位符一起使用?
csv 文件来自aws。
import tensorflow as tf
# https://s3.amazonaws.com/aml-sample-data/banking.csv
file1="/Users/Q/Downloads/banking.csv"
filename_queue = tf.train.string_input_producer([file1])
reader = tf.TextLineReader(skip_header_lines=1)
key, value = reader.read(filename_queue)
# record_defaults = [[""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [0]]
# record_defaults = [[0], [""], [""], [""], [""], [""], [""], [""], [""], [""], [0], [0], [0], [0], [""], [0.0], [0.0], [0.0], [0.0], [0.0], [0]]
record_defaults = [[0], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [0]]
cols = tf.decode_csv(value, record_defaults=record_defaults, field_delim=",")
features = tf.stack(cols[:-1])
with tf.Session() as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1000):
# Retrieve a single instance:
example, label = sess.run([features, cols[-1]])
coord.request_stop()
coord.join(threads)
错误信息
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/Q/Dropbox/code/Analyzing-Tea/tf-test.py
Traceback (most recent call last):
File "/Users/Q/Dropbox/code/Analyzing-Tea/tf-test.py", line 14, in <module>
features = tf.stack(cols[:-1])
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/array_ops.py", line 715, in stack
return gen_array_ops._pack(values, axis=axis, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1975, in _pack
result = _op_def_lib.apply_op("Pack", values=values, axis=axis, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 463, in apply_op
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [int32, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string] that don't all match.
Process finished with exit code 1