AI

TensorFlow - 画像ファイルをReaderクラスで読み込む

参考:TensorFlowのReaderクラスを使ってみる

こんな風にしたら単一ファイルを読み込めるらしい。

jpeg_r = tf.read_file(fname)
image = tf.image.decode_jpeg(jpeg_r, channels=3)

コード

import tensorflow as tf
import numpy as np
from PIL import Image
fpath = './img/sample_pic.jpg'
jpg = tf.read_file(fpath)
img = tf.image.decode_jpeg(jpg, channels=3)
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
img = sess.run(img)
Image.fromarray(np.uint8(img)).show()

結果