Tensorflow学习笔记-输入数据处理框架
来源:互联网 发布:什么软件个人房源多 编辑:程序博客网 时间:2024/05/20 21:47
通过前面几节的总结,Tensorflow关于TFRecord格式文件的处理、模型的训练的架构为:
1、获取文件列表、创建文件队列:http://blog.csdn.net/lovelyaiq/article/details/78711944
2、图像预处理:http://blog.csdn.net/lovelyaiq/article/details/78716325
3、合成Batch:http://blog.csdn.net/lovelyaiq/article/details/78727189
4、设计损失函数、梯度下降算法:http://blog.csdn.net/lovelyaiq/article/details/78616736
对应的代码流程如下:
# 创建文件列表,并通过文件列表来创建文件队列。在调用输入数据处理流程前,需要统一 # 所有的原始数据格式,并将它们存储到TFRecord文件中 # match_filenames_once 获取符合正则表达式的所有文件 files = tf.train.match_filenames_once('path/to/file-*-*') # 将文件列表生成文件队列 filename_queue = tf.train.string_input_producer(files,shuffle=True) reader = tf.TFRecordReader() _, serialized_example = reader.read(filename_queue) # image:存储图像中的原始数据 # label该样本所对应的标签 # width,height,channel features = tf.parse_single_example(serialized_example,features={ 'image' : tf.FixedLenFeature([],tf.string), 'label': tf.FixedLenFeature([], tf.int64), 'width': tf.FixedLenFeature([], tf.int64), 'heigth': tf.FixedLenFeature([], tf.int64), 'channel': tf.FixedLenFeature([], tf.int64) }) image, label = features['image'], features['label'] width, height = features['width'], features['height'] channel = features['channel'] # 将原始图像数据解析出像素矩阵,并根据图像尺寸还原糖图像。 decode_image = tf.decode_raw(image) decode_image.set_shape([width,height,channel]) # 神经网络的输入大小 image_size = 299 # 对图像进行预处理操作,比对亮度、对比度、随机裁剪等操作 distorted_image = propocess_train(decode_image,image_size,None) # shuffle_batch中的参数 min_after_dequeue = 1000 batch_size = 100 capacity = min_after_dequeue + 3*batch_size image_batch,label_batch = tf.train.shuffle_batch([distorted_image,label], batch_size=batch_size,capacity=capacity, min_after_dequeue=min_after_dequeue) logit = inference(image_batch) loss = cal_loss(logit,label_batch) train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss) with tf.Session() as sess: # 变量初始化 tf.global_variables_initializer().run() # 线程初始化和启动 coord = tf.train.Coordinator() theads = tf.train.start_queue_runners(sess=sess,coord=coord) for i in range(STEPS): sess.run(train_step) # 停止所有线程 coord.request_stop() coord.join(threads)
阅读全文
0 0
- Tensorflow学习笔记-输入数据处理框架
- 【TensorFlow】数据处理(输入数据处理框架)
- Tensorflow基础:多线程输入数据处理框架
- tensorflow15《TensorFlow实战Google深度学习框架》笔记-07图像数据处理 code
- tensorflow学习笔记(四十二):输入流水线
- 机器学习之TensorFlow框架学习笔记
- 深度学习框架TensorFlow学习笔记(1)
- tensorflow框架输入数据格式
- Tensorflow实战Google深度学习框架 笔记
- 【TensorFlow】框架学习笔记tensor(一)
- 【TensorFlow】数据处理(输入文件队列)
- 深度学习框架谷歌TensorFlow学习笔记一
- TensorFlow深度学习框架学习笔记(1)
- Tensorflow实战Google深度学习框架-学习笔记
- MFC学习笔记-数据处理
- TensorFlow深度学习框架
- TensorFlow深度学习框架
- TensorFlow深度学习框架
- 分布式编译以及如何加快编译速度
- k-近邻算法(kNN)
- 1039. Course List for Student (25)-PAT甲级真题
- A neural algorithm for a fundamental computing problem(求解基本计算问题的神经算法)
- HashMap原理详解
- Tensorflow学习笔记-输入数据处理框架
- 实现两个Intent之间跳转和数据传输
- ruby ActiveRecord追加
- delphi FMX图像的直方图匹配
- 比特币源码解读四
- Fragment 表示 Activity 中的行为或用户界面部分
- webView 收起和展开
- 安卓webview和JS交互,使用连接桥JsBridge进行连
- R语言——1初学