![](/img/trans.png)
[英]How to use the Tensorflow Dataset API to read files with different names without evaluating the filename string
[英]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.