TensorFlow01: 二进制文件读取
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了TensorFlow01: 二进制文件读取,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1871字,纯文字阅读大概需要3分钟。
内容图文
实现代码:
# 读取文件列表 file_name = os.listdir("../data/cifar/") file_list = [os.path.join("../data/ficar/",file) for file in file_name] # 构造文件名度列 file_queue = tf.train.string_input_producer(file_list) # 读取 reader = tf.FixedLengthRecordReader(32*32*3+1) key, value = reader.read(file_queue) print(value) # 解码 decoded = tf.decode_raw(value, tf.uint8) print(decoded) # 将目标值和特征值切开 label = tf.slice(decoded, [0], [1]) image = tf.slice(decoded, [1], [32*32*3]) print("label:", label) print("image:", image) # 调整图片的形状 image_reshape = tf.reshape(image, shape=[3, 32, 32]) print("image_reshape:", image_reshape) # 转置 image_transposed = tf.transpose(image_reshape, [1, 2, 0]) print("image_transposed:", image_transposed) # 调整图像类型 image_cast = tf.cast(image_transposed, tf.float32) # 批处理 label_batch,image_batch = tf.train.batch([label,image_cast], batch_size=100, num_threads=1, capacity=100) print("label_batch:", label_batch) print("image_batch:", image_batch) with tf.Session() as sess1: # print(sess1.run(label_batch))# 开启线程print("----------") coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(sess=sess1, coord=coord) print("threads:", threads) a, b = sess1.run([label_batch,image_batch]) print("label_batch+++++:", a) print("image_batch+++++:", b) print("999999") # 回收线程 coord.request_stop() coord.join(threads)
运行结果:
Tensor("ReaderReadV2:1", shape=(), dtype=string) Tensor("DecodeRaw:0", shape=(?,), dtype=uint8) label: Tensor("Slice:0", shape=(1,), dtype=uint8) image: Tensor("Slice_1:0", shape=(3072,), dtype=uint8) image_reshape: Tensor("Reshape:0", shape=(3, 32, 32), dtype=uint8) image_transposed: Tensor("transpose:0", shape=(32, 32, 3), dtype=uint8) label_batch: Tensor("batch:0", shape=(100, 1), dtype=uint8) image_batch: Tensor("batch:1", shape=(100, 32, 32, 3), dtype=float32
原文:https://www.cnblogs.com/jumpkin1122/p/11522000.html
内容总结
以上是互联网集市为您收集整理的TensorFlow01: 二进制文件读取全部内容,希望文章能够帮你解决TensorFlow01: 二进制文件读取所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。