栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Tensorflow读取带有标签的图像

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tensorflow读取带有标签的图像

使用

slice_input_producer
提供了一种更清洁的解决方案。切片输入生产者允许我们创建一个包含任意多个可分离值的输入队列。这个问题的片段如下所示:

def read_labeled_image_list(image_list_file):    """Reads a .txt file containing pathes and labeles    Args:       image_list_file: a .txt file with one /path/to/image per line       label: optionally, if set label will be pasted after each line    Returns:       List with all filenames in file image_list_file    """    f = open(image_list_file, 'r')    filenames = []    labels = []    for line in f:        filename, label = line[:-1].split(' ')        filenames.append(filename)        labels.append(int(label))    return filenames, labelsdef read_images_from_disk(input_queue):    """Consumes a single filename and label as a ' '-delimited string.    Args:      filename_and_label_tensor: A scalar string tensor.    Returns:      Two tensors: the depred image, and the string label.    """    label = input_queue[1]    file_contents = tf.read_file(input_queue[0])    example = tf.image.depre_png(file_contents, channels=3)    return example, label# Reads pfathes of images together with their labelsimage_list, label_list = read_labeled_image_list(filename)images = ops.convert_to_tensor(image_list, dtype=dtypes.string)labels = ops.convert_to_tensor(label_list, dtype=dtypes.int32)# Makes an input queueinput_queue = tf.train.slice_input_producer([images, labels],num_epochs=num_epochs,shuffle=True)image, label = read_images_from_disk(input_queue)# Optional Preprocessing or Data Augmentation# tf.image implements most of the standard image augmentationimage = preprocess_image(image)label = preprocess_label(label)# Optional Image and Label Batchingimage_batch, label_batch = tf.train.batch([image, label],         batch_size=batch_size)

又见generic_input_producer从TensorVision全输入管道的例子。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402165.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号