码迷,mamicode.com
首页 > 其他好文 > 详细

TensorFlow读取CSV数据

时间:2017-05-12 11:44:21      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:code   init   string   初始化   ring   ssi   initial   amp   runners   

代码来源于官方文档,做了一些小小的调整:

# -*- coding:utf-8 -*-
import tensorflow as tf

filename_queue = tf.train.string_input_producer(["file01.csv", "file02.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)

# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[1], [1], [1]]
col1, col2, col3 = tf.decode_csv(value, record_defaults = record_defaults)
features = tf.stack([col1, col2])

init_op = tf.global_variables_initializer()
local_init_op = tf.local_variables_initializer()  # local variables like epoch_num, batch_size 可以不初始化local
with tf.Session() as sess:
    sess.run(init_op)
    sess.run(local_init_op)

    # Start populating the filename queue.
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)

    for i in range(5):
        # Retrieve a single instance:
        example, label = sess.run([features, col3])
        print(example)
        print(label)

    coord.request_stop()
    coord.join(threads)

 

file01.csv 和 file02.csv 格式一样:

19,3,1
10,2,3
11,3,1
12,4,2
17,5,1
18,6,2
......

 

TensorFlow读取CSV数据

标签:code   init   string   初始化   ring   ssi   initial   amp   runners   

原文地址:http://www.cnblogs.com/hunttown/p/6844461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!