繁体   English   中英

如何从张量流中的字符串张量读取数据集名称

[英]How to read dataset names from string tensor in tensorflow

我是tensorflow的新手,我有一个张量(字符串类型),其中我存储了我想用于训练模型的所有必需图像的图像路径。

问题:如何读取张量排队然后批量处理。

我的方法是:给我错误

    img_names = dataset['f0']
    file_length = len(img_names)
    type(img_names)
    tf_img_names = tf.stack(img_names)
    filename_queue = tf.train.string_input_producer(tf_img_names, num_epochs=num_epochs, shuffle=False)
    wd=getcwd()
    print('In input pipeline')
    tf_img_queue = tf.FIFOQueue(file_length,dtypes=[tf.string])
    col_Image = tf_img_queue.dequeue(filename_queue)
    ### Read Image
    img_file = tf.read_file(wd+'/'+col_Image)
    image = tf.image.decode_png(img_file, channels=num_channels)
    image = tf.cast(image, tf.float32) / 255.
    image = tf.image.resize_images(image,[image_width, image_height])
    min_after_dequeue = 100
    capacity = min_after_dequeue + 3 * batch_size
    image_batch, label_batch = tf.train.batch([image, onehot], batch_size=batch_size, capacity=capacity, allow_smaller_final_batch = True, min_after_dequeue=min_after_dequeue)

错误: TypeError:期望的字符串或缓冲区'

我不知道我的方法是否正确

您不必创建另一个队列。 您可以定义一个能够为您排队元素的阅读器。 您可以尝试以下操作并评论该怎么做。

reader = tf.IdentityReader()
key, value = reader.read(filename_queue)
dir = tf.constant(wd)
path = tf.string_join([dir,tf.constant("/"),value])
img_file = tf.read_file(path)

并检查你正在喂食正确的路径,做

print(sess.run(img_file))

寻找您的反馈。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM