Tensor Flow shuffle_batch 的方式读csv文件的例子
2016-05-12 17:15
507 查看
用最简单的代码展示了一个tensor flow shuffle的方式读文件
代码
#coding=utf-8 import tensorflow as tf import numpy as np def readMyFileFormat(fileNameQueue): reader = tf.TextLineReader() key, value = reader.read(fileNameQueue) record_defaults = [[1], [1], [1]] col1, col2, col3 = tf.decode_csv(value, record_defaults = record_defaults) features = tf.pack([col1, col2]) label = col3 return features, label def inputPipeLine(fileNames = ["file0.csv", "file1.csv"], batchSize = 4, numEpochs = None): fileNameQueue = tf.train.string_input_producer(fileNames, num_epochs = numEpochs) example, label = readMyFileFormat(fileNameQueue) min_after_dequeue = 8 capacity = min_after_dequeue + 3 * batchSize exampleBatch, labelBatch = tf.train.shuffle_batch([example, label], batch_size = batchSize, num_threads = 3, capacity = capacity, min_after_dequeue = min_after_dequeue) return exampleBatch, labelBatch featureBatch, labelBatch = inputPipeLine(["file0.csv", "file1.csv"], batchSize = 4) with tf.Session() as sess: # Start populating the filename queue. coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) # Retrieve a single instance: try: #while not coord.should_stop(): while True: example, label = sess.run([featureBatch, labelBatch]) print example except tf.errors.OutOfRangeError: print 'Done reading' finally: coord.request_stop() coord.join(threads) sess.close()
file0.csv 的内容
9,1,1 10,2,3 11,3,1 12,4,2
file1.csv 的内容
1,1,7 2,2,8 3,3,5 4,4,9 5,5,5 6,6,1 7,7,2 8,8,4
相关文章推荐
- 背景 护眼
- 如何修改MySQL字符集
- 红糖水白糖水
- Mapped Statements collection does not contain value for
- http://blog.csdn.net/testcs_dn/article/details/45225413
- 大神是如何装逼的 之 vim插件使用taglist和nerdtree
- size()和length以及length()之间的用法
- Lucene中文分词以及关键字的高亮
- maven项目如何跳过某些junit test,或者指定执行部分junit test
- sql中的or的用法说明
- 微信方法整理1
- angular使用echarts折线图
- Spring mvc注解配置的背后
- Java入门第二季-学习笔记
- Cat 部署
- hdu2844 Coins(DP)
- 条形码、二维码扫一扫和生成二维码采用ZXing3.0开源库在android studio中实现
- Sharedprefernces的使用总结?
- 一个开源.net混淆器——ConfuserEx (收藏)
- 详解.NET IL代码