ValueError:无法推断Tensor的排名:Tensor(" fifo_queue_Dequeue:0",dtype = float32)

时间:2017-10-13 11:53:13

标签: python-2.7 tensorflow queue training-data tensorflow-gpu

我正在尝试加载每个不同大小的批量图像(具体来说,它们来自pascal voc数据集)。 source_images.npy文件包含不同高度,宽度但相同通道的图像。我做错了什么?有没有其他方法可以发送不同大小的图像?

这是我的代码:

def feed(images, im, epochs=None):
    epochs_elapsed = 0
    while epochs is None or epochs_elapsed < epochs:
        for i in range(len(images)):
            yield {im: images[i]}
        epochs_elapsed += 1


def tf_ops(images, capacity=200):
    im = tf.placeholder(tf.float32)
    queue = tf.FIFOQueue(capacity, [tf.float32])
    enqueue_op = queue.enqueue(im)
    fqr = FeedingQueueRunner(queue, [enqueue_op],
                             feed_fns=[feed(images,im).next()])
    tf.train.add_queue_runner(fqr)
    return queue.dequeue()

source_images = np.load('source_images.npy')
source_images=source_images.tolist()
source_im= tf_ops(source_images)
source_im_batch = tf.train.batch([source_im],batch_size=128,capacity=200, dynamic_pad=True)

错误:

source_im_batch = tf.train.batch([source_im], batch_size=128,capacity=200, dynamic_pad=True)
File "/home/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 872, in batch
name=name)
File "/home/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 655, in _batch
shapes = _shapes([tensor_list], shapes, enqueue_many)
File "/home/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 598, in _shapes
raise ValueError("Cannot infer Tensor's rank: %s" % tl[i])
ValueError: Cannot infer Tensor's rank: Tensor("fifo_queue_Dequeue:0", dtype=float32)

0 个答案:

没有答案