源程序代码如下:
"""
__author__="dazhi"
2021/3/18-14:10
"""
import os
import tensorflow as tf
def picture_read(file_list):
tf.compat.v1.disable_eager_execution()
file_queue = tf.compat.v1.train.string_input_producer(file_list)
reader = tf.compat.v1.WholeFileReader()
key,value = reader.read(file_queue)
image = tf.image.decode_jpeg(value)
image_resize = tf.compat.v1.image.resize_images(image,[200,200])
image_resize.set_shape(shape=[200,200,3])
image_bach = tf.compat.v1.train.batch([image_resize],batch_size=100,num_threads=1,capacity=100)
with tf.compat.v1.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.compat.v1.train.start_queue_runners(sess=sess,coord=coord)
key_new,value_new,image_new,image_resize_new,image_bach_new = sess.run([key,value,image,image_resize,image_bach])
coord.request_stop()
coord.join(threads)
print("image_bach_new = ",image_bach_new)
return None
if __name__ == '__main__':
filename = os.listdir("./dog")
file_list = [os.path.join("./dog/",file) for file in filename]
picture_read(file_list)
各个变量输出结果如下:(输出位置在代码中已经注释了)
filename
file_list
key
value
key_new
value_new
image
image_new
最后读入图片并转为张量的结果是:
用到的dog文件夹:
用到的dog文件~~~~~(点我)