简体   繁体   中英

How to read dataset names from string tensor in tensorflow

I'm new to tensorflow, I have a tensor(string type) in which I have stored image paths of all the required images that i want to use for training a model.

Question : How to read the tensor to queue and then batch it.

My Approach is: Is giving me error

    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)

Error : TypeError: expected string or buffer'

I dont know if my approach is right or not

You don't have to create another Queue. You can define a reader that will dequeue elements for you. You can try the following and comment how that goes.

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)

and to check you're feeding correct paths, do

print(sess.run(img_file))

Looking for your feedback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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