tensorflow随笔-读取图像文件数据(1)
生活随笔
收集整理的这篇文章主要介绍了
tensorflow随笔-读取图像文件数据(1)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
# -*- coding: utf-8 -*-
"""
Created on Tue May 7 18:29:30 2019@author: liuxing
@email:lx@lxaipro.com
"""
import tensorflow as tf
import os#指定文件列表
imageFileName=[os.getcwd()+'/pic.jpg']fileNameQueue=tf.train.string_input_producer(imageFileName)
imageReader=tf.WholeFileReader()
imageFileN,imageFile=imageReader.read(fileNameQueue)
image=tf.image.decode_jpeg(imageFile)init_op=tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())with tf.Session() as sess:sess.run(init_op)fileCount=len(imageFileName)print("===============================")#开启协调器coord=tf.train.Coordinator()#启动队列填充threads=tf.train.start_queue_runners(coord=coord,sess=sess)try:i=0while i < fileCount:imageData=sess.run(image)print(imageData)print("--------")i=i+1except tf.errors.OutOfRangeError:print("Done!!!")finally:coord.request_stop()coord.join(threads)print("reading has finished.")
输出结果如下:
===============================[[[ 50 149 234][ 50 149 234][ 50 149 234]...[ 32 132 228][ 32 132 228][ 32 132 228]][[ 51 150 235][ 51 150 235][ 51 150 235]...[ 32 132 228][ 32 132 228][ 32 132 228]][[ 52 151 236][ 52 151 236][ 52 151 236]...[ 33 133 229][ 33 133 229][ 33 133 229]]...[[ 30 35 39][ 27 32 36][ 23 27 30]...[ 97 115 89][ 78 96 72][ 68 86 62]][[ 22 26 27][ 23 27 28][ 28 29 31]...[ 73 93 65][ 31 51 23][ 14 34 6]][[ 32 36 35][ 37 41 40][ 46 48 47]...[ 72 96 64][ 58 82 50][ 51 75 43]]]--------reading has finished.输出文件名及文件内容:
# -*- coding: utf-8 -*- """ Created on Tue May 7 18:29:30 2019@author: liuxing @email:lx@lxaipro.com """ import tensorflow as tf import os#指定文件列表 imageFileName=[os.getcwd()+'/pic.jpg']fileNameQueue=tf.train.string_input_producer(imageFileName) imageReader=tf.WholeFileReader() imageFileN,imageFile=imageReader.read(fileNameQueue) image=tf.image.decode_jpeg(imageFile)init_op=tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())with tf.Session() as sess:sess.run(init_op)fileCount=len(imageFileName)#开启协调器coord=tf.train.Coordinator()#启动队列填充threads=tf.train.start_queue_runners(coord=coord,sess=sess)try:i=0while i < fileCount:imageData=sess.run(image)print("===============================")print(sess.run(imageFileN))print("===============================")print(imageData)print("--------")i=i+1except tf.errors.OutOfRangeError:print("Done!!!")finally:coord.request_stop()coord.join(threads)print("reading has finished.")输出结果如下:
=============================== b'E:\\pro\\learn/pic.jpg' =============================== [[[ 50 149 234][ 50 149 234][ 50 149 234]...读取多个图像文件
# -*- coding: utf-8 -*- """ Created on Tue May 7 18:29:30 2019@author: liuxing @email:lx@lxaipro.com """ import tensorflow as tf import os#指定文件列表 imageFileName=[os.getcwd()+'/1.jpg',os.getcwd()+'/2.jpg']fileNameQueue=tf.train.string_input_producer(imageFileName) imageReader=tf.WholeFileReader() imageFileN,imageFile=imageReader.read(fileNameQueue) image=tf.image.decode_jpeg(imageFile)init_op=tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())with tf.Session() as sess:sess.run(init_op)fileCount=len(imageFileName)#开启协调器coord=tf.train.Coordinator()#启动队列填充threads=tf.train.start_queue_runners(coord=coord,sess=sess)try:i=0while i < fileCount:imageData=sess.run(image)print("===============================")print(sess.run(imageFileN))print("===============================")print(imageData)print("--------")i=i+1except tf.errors.OutOfRangeError:print("Done!!!")finally:coord.request_stop()coord.join(threads)print("reading has finished.")输出结果如下:
=============================== b'E:\\pro\\learn/2.jpg' =============================== [[[ 50 149 234][ 50 149 234][ 50 149 234]...[ 72 96 64][ 58 82 50][ 51 75 43]]] -------- =============================== b'E:\\pro\\learn/1.jpg' =============================== [[[250 254 253][250 254 253][250 254 253]...[250 254 253][250 254 253][250 254 253]]] -------- reading has finished.生成队列文件
# -*- coding: utf-8 -*- """ Created on Tue May 7 18:29:30 2019@author: liuxing @email:lx@lxaipro.com """ import tensorflow as tf import os#tf.train.match_filenames_once 函数产生文件名列表 imageFN=os.getcwd()+'/*.jpg' imageFileName=tf.train.match_filenames_once(imageFN) fileNameQueue=tf.train.string_input_producer(imageFileName) imageReader=tf.WholeFileReader() imageFileN,imageFile=imageReader.read(fileNameQueue) image=tf.image.decode_jpeg(imageFile)init_op=tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())with tf.Session() as sess:sess.run(init_op)fileCount=len(sess.run(imageFileName))#开启协调器 coord=tf.train.Coordinator() #启动队列填充 threads=tf.train.start_queue_runners(coord=coord,sess=sess) try:i=0while i < fileCount:imageData=sess.run(image)print("===============================")print(sess.run(imageFileN))print("===============================")print(imageData)print("--------")i=i+1 except tf.errors.OutOfRangeError:print("Done!!!") finally:coord.request_stop()coord.join(threads)print("reading has finished.")总结
以上是生活随笔为你收集整理的tensorflow随笔-读取图像文件数据(1)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: micropython随笔-hello,
- 下一篇: 单行文字、多行文字溢出时省略号表示的多种