tensorflow io 图片读取

来源:互联网 发布:淘宝全职客服工资多少 编辑:程序博客网 时间:2024/06/04 19:52

单个图片读取

png格式的图片也可替换为jpeg格式,但是函数要相应修改一下

filename_queue = tf.train.string_input_producer([‘/Users/HANEL/Desktop/tf.png’]) # list of files to read

reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)

my_img = tf.image.decode_png(value) # use png or jpg decoder based on your files.

init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)

# Start populating the filename queue.

coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)

for i in range(1): #length of your filename list
image = my_img.eval() #here is your image Tensor :)

print(image.shape)
Image.fromarray(np.asarray(image)).show()

coord.request_stop()
coord.join(threads)

原创粉丝点击