[英]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. 我是tensorflow的新手,我有一个张量(字符串类型),其中我存储了我想用于训练模型的所有必需图像的图像路径。
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' 错误: TypeError:期望的字符串或缓冲区'
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. 寻找您的反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.