概述
最近,心血来潮搞一搞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--数据读取篇features = [features]W1=tf.Variable(tf.truncated_normal([6,1]))result = tf.matmul(example_batch,W1)**的全部内容,希望文章能够帮你解决tensorflow--数据读取篇features = [features]W1=tf.Variable(tf.truncated_normal([6,1]))result = tf.matmul(example_batch,W1)**所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复