我正在使用Tensorflow构建标准图像分类模型.为此,我有输入图像,每个图像都分配有一个标签({0,1}中的数字).因此,可以使用以下格式将数据存储在列表中:
/path/to/image_0 label_0
/path/to/image_1 label_1
/path/to/image_2 label_2
...
Run Code Online (Sandbox Code Playgroud)
我想使用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)
Run Code Online (Sandbox Code Playgroud)
但是,标签在该过程中丢失,因为图像数据被有意地作为输入管道的一部分混洗.通过输入队列将标签与图像数据一起推送的最简单方法是什么?