Python 使用TensorFlow读取CSV文件
我正在尝试从CSV文件中读取张量并打印它。我听从了建议,但脚本仍然挂着。data.csv由一行组成:Python 使用TensorFlow读取CSV文件,python,tensorflow,Python,Tensorflow,我正在尝试从CSV文件中读取张量并打印它。我听从了建议,但脚本仍然挂着。data.csv由一行组成: 1.5,2.5 下面是读取它的代码: datafile = tf.train.string_input_producer([os.path.join(os.getcwd(), "data.csv")]) reader = tf.TextLineReader() _, value = reader.read(datafile) record_defaults = [[1], [1]] col1,
1.5,2.5
下面是读取它的代码:
datafile = tf.train.string_input_producer([os.path.join(os.getcwd(), "data.csv")])
reader = tf.TextLineReader()
_, value = reader.read(datafile)
record_defaults = [[1], [1]]
col1, col2 = tf.decode_csv(value, record_defaults=record_defaults)
result = tf.stack([col1, col2])
config = tf.ConfigProto(inter_op_parallelism_threads=2)
with tf.Session() as sess:
print(sess.run(result))
有什么想法吗?你在引用的答案中遗漏了这一部分。如果不添加协调器并启动队列运行程序,队列将永远不会排队,会话将挂起,等待元素排队
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(1200):
# Retrieve a single instance:
example, label = sess.run([features, col5])
coord.request_stop()
coord.join(threads)
啊,谢谢。我添加了配置行,因为另一篇帖子推荐了它。