0

在下面的示例中,每次运行时sess.run([image, label]),都会返回队列中的不同样本,因此返回不同的样本np_image

有没有办法让我slim.queues.QueueRunners知道我想在出队操作发生之前使用(运行)相同的样本倍数?

我问的原因是我有一个不适合我的 VRAM 的大型操作。我必须将大操作分解为几个小操作,并在feed_dict每次运行小操作时提供不同的操作。但是,当我run进行小操作时,image更改会破坏代码。将所有小操作放在一个列表和run列表中对我来说不起作用,因为 VRAM 大小是限制。

谢谢!

import tensorflow as tf
import numpy as np
slim = tf.contrib.slim

from datasets import dataset_utils
from tensorflow.python.ops import control_flow_ops
from datasets import dataset_factory
from deployment import model_deploy
from nets import nets_factory
from preprocessing import preprocessing_factory

with tf.Graph().as_default():
    dataset = dataset_factory.get_dataset('cifar10', 'train','/home/user/dataset/cifar10')

    provider = slim.dataset_data_provider.DatasetDataProvider(
              dataset,
              num_readers=1,
              common_queue_capacity=256,
              common_queue_min=128)
    [image, label] = provider.get(['image', 'label'])

    image_preprocessing_fn = preprocessing_factory.get_preprocessing(
            'cifarnet',
            is_training=True)

    images, labels = tf.train.batch([image, label],
      batch_size=32,
      num_threads=1,
      capacity=64)

    with tf.Session() as sess:    
        with slim.queues.QueueRunners(sess):
            for i in range(3):
                #in every iteration, the tensor 'image' will be different
                #the np_image value will be different as well
                np_image, np_label = sess.run([image, label])
4

1 回答 1

1

目前不支持队列的 Peek 操作,讨论见 https://github.com/tensorflow/tensorflow/issues/7880

一种解决方法是重组代码以从tf.Variable对象中获取值,而不是从tf.dequeue. 像这样的IE

x = tf.Variable(queue.dequeue())
y = x+2
sess.run(x.initializer)
sess.run(y) 
sess.run(y)  # same value
sess.run(x.initializer)
sess.run(y)  # new value
于 2017-05-15T03:14:50.630 回答