TensorFlow读取tfrecords数据
来源:互联网 发布:mysql join 默认值 编辑:程序博客网 时间:2024/06/05 00:09
因为要用到TensorFlow,自然少不了数据的读取,这里我自己写了一个tfrecords的数据的读取函数
"""Created on Wed Jun 28 13:56:35 2017@author:liao"""import tensorflow as tfimport numpy as npfrom PIL import Imageimport pprint as ppimport os#cwd = os.getcwd()#file_path=[cwd+os.sep+'emotion-tfrecord'+os.sep+'emotion_image_data.tfrecords']#fileNameQue = tf.train.string_input_producer(file_path)#从文件名列表,生成文件名队列#reader = tf.TFRecordReader()#用tfrecords专用的reader去读#key,value = reader.read(fileNameQue)#features = tf.parse_single_example(value,features={ 'label': tf.FixedLenFeature([], tf.int64),# 'img' : tf.FixedLenFeature([], tf.string),})##img = tf.decode_raw(features["img"], tf.uint8)#image_raw=tf.reshape(img,[48,48])#如果后面要接卷积神经网络的话,就化成这样的形式#labels = tf.cast(features["label"], tf.int32)###使用样本队列,让本队列自动打包,发送#num_preprocess_threads = 16#image, label = tf.train.shuffle_batch([image_raw,labels], batch_size = batch_size, num_threads=num_preprocess_threads, min_after_dequeue = 1, capacity = 10)###init = tf.global_variables_initializer()#注意这里一定要有这初始化#with tf.Session() as sess:## sess.run(init)# #线程协调器,控制打包读取的线程# coord = tf.train.Coordinator()# #让读取队列开始工作# threads = tf.train.start_queue_runners(coord=coord)# #从队列读取图像和标签# images,labels=sess.run([image,label])# print(images,labels)### coord.request_stop()# coord.join(threads)def read_tfrecords(file_path,batch_size): fileNameQue = tf.train.string_input_producer([file_path]) reader = tf.TFRecordReader()#用tfrecords专用的reader去读 key,value = reader.read(fileNameQue) features = tf.parse_single_example(value,features={ 'label': tf.FixedLenFeature([], tf.int64), 'img' : tf.FixedLenFeature([], tf.string),}) img = tf.decode_raw(features["img"], tf.uint8) image_raw=tf.reshape(img,[1,48,48])#如果后面要接卷积神经网络的话,就化成这样的形式[depth,height,width] image_raw = tf.transpose(image_raw, (1,2,0))# image_raw = tf.cast(image_raw, tf.float32)# 归一化操作 image_raw= tf.image.per_image_standardization(image_raw)# labels = tf.cast(features["label"], tf.int32) #使用样本队列,让本队列自动打包,发送 num_preprocess_threads = 16 image, label = tf.train.shuffle_batch([image_raw,labels], batch_size = batch_size, num_threads=num_preprocess_threads, min_after_dequeue = 1, capacity = 1024) return image, tf.reshape(label, [batch_size])屏蔽掉的部分是测试程序。有关数TensorFlow的数据的读取过程可以参考点击打开链接
阅读全文
0 0
- TensorFlow读取tfrecords数据
- tensorflow数据读取之tfrecords
- 机器学习: TensorFlow 的数据读取与TFRecords 格式
- tensorflow读取SVHN数据集转为TFrecords格式
- 由浅入深之Tensorflow(3)----数据读取之TFRecords
- 由浅入深之Tensorflow(3)----数据读取之TFRecords
- Tensorflow分批量读取tfrecords
- 数据读取之TFRecords
- Tensorlfow 数据读取之TFRecords
- Tensorflow中使用TFRecords高效读取数据--结合NLP数据实践
- Tensorflow中使用TFRecords高效读取数据--结合NLP数据实践
- Tensorflow之构建自己的图片数据集TFrecords
- Tensorflow构建自己的图片数据集TFrecords
- Tensorflow之构建自己的图片数据集TFrecords(精)
- Tensorflow之构建自己的图片数据集TFrecords
- Tensorflow构建自己的图片数据集TFrecords
- tensorflow官网Cifar-10改为自己的TFRecords数据集
- 制作tensorflow标准数据集即制作.tfrecords格式文件
- 20170709_网络层的题目、子网划分、子网掩码、CIDR技术
- HIVE和HBASE区别
- Servlet学习
- Volley是如何把response deliver到Main Thread的?
- Tomcat配置及使用
- TensorFlow读取tfrecords数据
- 玩转消息队列之C/C++代码
- SPOJ QTREE
- JVM内存模型
- 段落、链接、图片标签的使用
- HDU 1058
- 【JWT】JWT+HA256加密 Token验证
- Linux LCD驱动(一)——硬件分析和FrameBuffer
- Python的GUI编程入门