【问题标题】:How to read dataset names from string tensor in tensorflow如何从张量流中的字符串张量读取数据集名称
【发布时间】:2017-11-02 02:05:44
【问题描述】:

我是 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:预期的字符串或缓冲区'

不知道我的做法对不对

【问题讨论】:

    标签: python tensorflow tensorflow-serving tensorflow-gpu


    【解决方案1】:

    您不必创建另一个队列。您可以定义一个将为您出列元素的阅读器。您可以尝试以下方法并发表评论。

    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))
    

    正在寻找您的反馈。

    【讨论】:

    • 如果我使用 numpy genfromtxtcsv_file = np.genfromtxt(args.dataset, delimiter=',',skip_header=1,usecols=(0,1,2,3,4,5), dtype=None) 读取了一个 csv 文件,如何使用 string_input_producer 对文件进行排队和批处理......
    • 你不必使用 numpy 阅读。使用 tf.TextLineReader() 并将每一行解析为您需要的内容并加载图像。看看这个:stackoverflow.com/questions/37091899/…
    猜你喜欢
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2018-09-29
    • 1970-01-01
    • 2016-08-10
    • 2018-06-25
    • 2020-10-30
    相关资源
    最近更新 更多