私のローカルディスク上のファイルから10個のイメージのバッチを読み込んでいる次のコードがあります。イメージの読み取りバッチは非常に遅いですか?
問題は、コードが非常に遅く実行されているようです。完了までには5〜6分かかります。イメージを含むディレクトリには、 25.000枚の画像。
コードは正しいですか、何か愚かなことをしましたか?
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import tensorflow as tf
image_width = 202
image_height = 180
num_channels = 3
filenames = tf.train.match_filenames_once("./train/Resized/*.jpg")
def read_image(filename_queue):
image_reader = tf.WholeFileReader()
key, image_filename = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_filename)
image.set_shape((image_height, image_width, 3))
return image
def input_pipeline(filenames, batch_size, num_epochs=None):
filename_queue = tf.train.string_input_producer(filenames, num_epochs=num_epochs, shuffle=True)
input_image = read_image(filename_queue)
min_after_dequeue = 10000
capacity = min_after_dequeue + 3 * batch_size
image_batch = tf.train.shuffle_batch(
[input_image], batch_size=batch_size, capacity=capacity,
min_after_dequeue=min_after_dequeue)
return image_batch
new_batch = input_pipeline(filenames, 10)
with tf.Session() as sess:
# Required to get the filename matching to run.
tf.global_variables_initializer().run()
# Coordinate the loading of image files.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
b1 = sess.run(new_batch)
# Finish off the filename queue coordinator.
coord.request_stop()
coord.join(threads)
問題を絞り込むために、犯人と思われる各関数呼び出しに時間を掛けることができます。 'image_reader.read(..)'と 'tf.image.decode_jpeg(..)'のようなものです。 – kaufmanu