Tensorflow 如何处理输入管道中的标签?
我有一个图像的名称和标签作为列表,我想得到一批64个图像/标签。我可以以正确的方式获得图像,但对于标签,其尺寸是(648126)。每列都有64次相同的元素。行由8126个原始标签值组成,而不会被洗牌 我理解的问题是,对于每个图像tf.train.shuffle_批处理,都会考虑8126元素标签向量。但是,如何为每个图像只传递单个元素呢Tensorflow 如何处理输入管道中的标签?,tensorflow,Tensorflow,我有一个图像的名称和标签作为列表,我想得到一批64个图像/标签。我可以以正确的方式获得图像,但对于标签,其尺寸是(648126)。每列都有64次相同的元素。行由8126个原始标签值组成,而不会被洗牌 我理解的问题是,对于每个图像tf.train.shuffle_批处理,都会考虑8126元素标签向量。但是,如何为每个图像只传递单个元素呢 def _get_images(shuffle=True): """Gets the images and labels as a batch"""
def _get_images(shuffle=True):
"""Gets the images and labels as a batch"""
#get image and label list
_img_names,_img_class = _get_list() #list of image names and labels
filename_queue = tf.train.string_input_producer(_img_names)
#reader
image_reader = tf.WholeFileReader()
_, image_file = image_reader.read(filename_queue)
#decode jpeg
image_original = tf.image.decode_jpeg(image_file)
label_original = tf.convert_to_tensor(_img_class,dtype=tf.int32)
#print label_original
#image preprocessing
image = tf.image.resize_images(image_original, [224,224])
float_image = tf.cast(image,dtype=tf.float32)
float_image = tf.image.per_image_standardization(image)
#set the shape
float_image.set_shape((224, 224, 3))
#label_original.set_shape([8126]) #<<<<<=========== causes (64,8126) dimension label without shuffle
#parameters for shuffle
batch_size = 64
num_preprocess_threads = 16
num_examples_per_epoch = 8000
min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(num_examples_per_epoch *
min_fraction_of_examples_in_queue)
if shuffle:
images_batch, label_batch = tf.train.shuffle_batch(
[float_image,label_original],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size,
min_after_dequeue=min_queue_examples)
else:
images_batch, label_original = tf.train.batch(
[float_image,_img_class],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size)
return images_batch,label_batch
def\u获取图像(shuffle=True):
“”“将图像和标签作为批处理获取”“”
#获取图像和标签列表
_img_名称,_img_类=_get_list()#图像名称和标签列表
filename\u queue=tf.train.string\u input\u producer(\u img\u name)
#读取器
image\u reader=tf.WholeFileReader()
_,image\u file=image\u reader.read(文件名\u队列)
#解码jpeg
image\u original=tf.image.decode\u jpeg(图像文件)
label_original=tf.convert_to_tensor(_img_类,dtype=tf.int32)
#打印标签或原件
#图像预处理
image=tf.image.resize\u图像(原始图像,[224224])
float_image=tf.cast(image,dtype=tf.float32)
float\u image=tf.image.per\u image\u标准化(image)
#定形
浮动图像。设置形状((2242243))
#label_original.set_shape([8126])35;您可以使用tf.train.slice_input_producer
# here _img_class should be a list
labels_queue = tf.train.slice_input_producer([_img_class])
...
images_batch, label_batch = tf.train.shuffle_batch(
[float_image,labels_queue],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size,
min_after_dequeue=min_queue_examples)
您可以使用tf.train.slice\u input\u producer
# here _img_class should be a list
labels_queue = tf.train.slice_input_producer([_img_class])
...
images_batch, label_batch = tf.train.shuffle_batch(
[float_image,labels_queue],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size,
min_after_dequeue=min_queue_examples)
格雷特!!谢谢非常感谢!格雷特!!谢谢非常感谢!