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,
- 下一篇: 【计算机系统】指令流水线