欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

6.2.3 TensorFlow 读取图片

程序员文章站 2022-03-20 14:48:08
...

《TensorFlow 与卷积神经网络 (从算法到入门)》学习笔记

import tensorflow as tf
import numpy as np


file_1 = '/Users/manmi/Documents/GitHub/tensorflow/image_1.jpeg'
file_2 = '/Users/manmi/Documents/GitHub/tensorflow/image_2.jpeg'
files = [file_1, file_2]

imgs_list_tf = tf.convert_to_tensor(files, dtype=tf.string)

[img_path_tf] = tf.train.slice_input_producer([imgs_list_tf])

img_data_tf = tf.read_file(img_path_tf)

img_tf = tf.image.decode_jpeg(img_data_tf, channels=3)

with tf.Session() as sess:
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)

    for i in range(2):
        img = sess.run(img_tf)
        img = np.array(img)
        print(np.shape(img))

    coord.request_stop()
    coord.join(threads)