tensorflow--数据读取篇

最近,心血来潮搞一搞tensorflow,看着《tensorflow实战》码了几个简单的小网络,自以为蛮简单啊,当自己开始从头开始构建自己网络时候,就开始怀疑人生了。自己的数据读取都是一个大问题,今天解决了使用tensorflow读取csv文本数据,写到博客做个笔记。
`#!/usr/bin/env python2
# -- coding: utf-8 --
“””
Created on Tue Oct 17 08:24:47 2017

@author: wp
“””
import numpy as np
import pandas as pd
import tensorflow as tf

filename_queue = tf.train.string_input_producer([“feature/test.csv”])

reader = tf.TextLineReader()
key, value = reader.read(filename_queue)

record_defaults = [[0] for iter in range(2)]
features= tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.to_float(features)

batch

batch_size = 1
mini_after_dequeue = 2
capacity = mini_after_dequeue+3*batch_size

example_batch,label_batch = tf.train.shuffle_batch([features[0],features[1]],batch_size = batch_size,capacity=capacity,min_after_dequeue=mini_after_dequeue)

features = [features]

W1=tf.Variable(tf.truncated_normal([6,1]))

result = tf.matmul(example_batch,W1)**

with tf.Session() as sess:
init =tf.global_variables_initializer()
sess.run(init)
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
try:
for iter in range(5):
print sess.run([example_batch,label_batch])
print sess.run(features)
except tf.errors.OutOfRangeError:
print ‘Done training – epoch limit reached’
finally:
coord.request_stop()
`

你可能感兴趣的:(tensorflow)