1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > tensorflow随笔-读取图像文件数据(1)

tensorflow随笔-读取图像文件数据(1)

时间:2023-02-03 01:17:45

相关推荐

tensorflow随笔-读取图像文件数据(1)

# -*- coding: utf-8 -*-"""Created on Tue May 7 18:29:30 @author: liuxing@email:lx@"""import tensorflow as tfimport 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 @author: liuxing@email:lx@"""import tensorflow as tfimport 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 @author: liuxing@email:lx@"""import tensorflow as tfimport 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 @author: liuxing@email:lx@"""import tensorflow as tfimport 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+1except tf.errors.OutOfRangeError:print("Done!!!")finally:coord.request_stop()coord.join(threads)print("reading has finished.")

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。