日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/12 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。