Tensorflow读取带有标签的图像

我正在使用Tensorflow构建标准的图像分类模型。为此,我有输入图像,每个图像都分配了一个标签({0,1}中的数字)。因此,可以使用以下格式将数据存储在列表中:


/path/to/image_0 label_0

/path/to/image_1 label_1

/path/to/image_2 label_2

...

我想使用TensorFlow的排队系统读取我的数据并将其输入到我的模型中。忽略标签,可以使用string_input_producer和轻松实现wholeFileReader。这里的代码:


def read_my_file_format(filename_queue):

  reader = tf.WholeFileReader()

  key, value = reader.read(filename_queue)

  example = tf.image.decode_png(value)

  return example


#removing label, obtaining list containing /path/to/image_x

image_list = [line[:-2] for line in image_label_list]


input_queue = tf.train.string_input_producer(image_list)                                                     

input_images = read_my_file_format(input_queue)

但是,在该过程中,标签丢失了,因为图像数据作为输入管道的一部分被有意地改组了。通过输入队列将标签和图像数据一起推入的最简单方法是什么?


呼啦一阵风
浏览 1280回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python