我在下面提到的代碼中收到此錯誤。請幫助我解決這個問題。 這段代碼每次運行這段代碼時都會打印變量的批次數。我無法找出錯誤。在張量流中使用隊列的輸入流水線中的錯誤
OutOfRangeError異常(參見上述用於回溯):FIFOQueue '_2_batch/fifo_queue' 被關閉,並且沒有足夠的元件 (請求15,電流大小0)[[節點:批次= QueueDequeueManyV2 [component_types = [DT_FLOAT] ,timeout_ms = -1, _device = 「/作業:本地主機/複製:0 /任務:0/CPU:0」](批次/ fifo_queue,批次/ N)]]
import tensorflow as tf
import numpy as np
import os
batch_size = 16
min_queue = 256
def load_image():
length = calculate_size("./Coco_subset_5356")
names = tf.train.match_filenames_once("./Coco_subset_5356/*.jpg")
# Extracted names from the file
filename_queue = tf.train.string_input_producer(names)
#Initialised the File reader
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
my_img = tf.image.decode_jpeg(value, channels = 3)
my_img = tf.image.resize_images(my_img, [256,256])
my_img.set_shape((256,256,3))
print(length)
images = tf.train.batch(
[my_img],
batch_size=batch_size,
num_threads=1,
capacity=min_queue + 3*batch_size)
print(images)
with tf.Session() as sess:
#sess.run(init_op)
tf.local_variables_initializer().run()
#print(tf.get_collection(tf.GraphKeys.LOCAL_VARIABLES))
#For coordination between queue runner and the reader
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord = coord)
for j in range(length/batch_size):
#optimizer.run(feed_dict={input_batch: images[i])
x = sess.run(images)
print(j)
print(x.shape)
coord.request_stop()
coord.join(threads)
def calculate_size(img_dir):
file = []
for subdir, dirs, files in os.walk(img_dir):
for i in files:
i = os.path.join(img_dir, i)
file.append(i)
length = len(file)
return length
load_image()
我有一個類似的問題,在我的情況下,它是一些圖像沒有得到正確解碼(在我的數據集中,我有1x1像素的圖像,設法通過過濾過程..)。你確定*所有*你的圖像可以正確打開並解碼爲jpg文件嗎? (它們也不能被截斷,默認情況下tensorflow會在處理截斷圖像時引發錯誤) – GPhilo
目錄中的* .jpg文件的數量是多少?它是15的倍數嗎?如果在'tf.train.batch'方法中設置'allow_smaller_final_batch = True'會怎樣? – npf
你也不介意編輯你的問題,使錯誤更具可讀性(例如使用>標記)? – npf