私はこの問題を何週間も抱えています。私は画像ファイル名のリストから画像バッチを作成したい。ファイル名リストをキューに挿入し、リーダーを使用してファイルを取得します。次に、リーダーはファイル名と読み取られたイメージファイルを返します。バッチ作成時にTensorflowが画像とラベルを混ぜる
私の問題は、デコードされたjpgとリーダーからのラベルを使ってバッチを作成すると、tf.train.shuffle_batch()は画像とファイル名を混ぜて、ラベルの順序が間違っていることです。イメージファイル。私がキュー/ shuffle_batchに間違っていることがありますか?また、正しいファイルの正しいラベルがバッチに出てくるように修正するにはどうしたらいいですか?
多くの感謝!
import tensorflow as tf
from tensorflow.python.framework import ops
def preprocess_image_tensor(image_tf):
image = tf.image.convert_image_dtype(image_tf, dtype=tf.float32)
image = tf.image.resize_image_with_crop_or_pad(image, 300, 300)
image = tf.image.per_image_standardization(image)
return image
# original image names and labels
image_paths = ["image_0.jpg", "image_1.jpg", "image_2.jpg", "image_3.jpg", "image_4.jpg", "image_5.jpg", "image_6.jpg", "image_7.jpg", "image_8.jpg"]
labels = [0, 1, 2, 3, 4, 5, 6, 7, 8]
# converting arrays to tensors
image_paths_tf = ops.convert_to_tensor(image_paths, dtype=tf.string, name="image_paths_tf")
labels_tf = ops.convert_to_tensor(labels, dtype=tf.int32, name="labels_tf")
# getting tensor slices
image_path_tf, label_tf = tf.train.slice_input_producer([image_paths_tf, labels_tf], shuffle=False)
# getting image tensors from jpeg and performing preprocessing
image_buffer_tf = tf.read_file(image_path_tf, name="image_buffer")
image_tf = tf.image.decode_jpeg(image_buffer_tf, channels=3, name="image")
image_tf = preprocess_image_tensor(image_tf)
# creating a batch of images and labels
batch_size = 5
num_threads = 4
images_batch_tf, labels_batch_tf = tf.train.batch([image_tf, label_tf], batch_size=batch_size, num_threads=num_threads)
# running testing session to check order of images and labels
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
print image_path_tf.eval()
print label_tf.eval()
coord.request_stop()
coord.join(threads)
ああ、あなたが正しいです!これはまさに問題です。どうもありがとうございます! –