我将张量流与 Titan-X GPU 一起使用,并且我注意到,当我运行 CIFAR10 示例时,Volatile GPU-utilization
稳定在 30% 左右,而当我训练自己的模型时,Volatile GPU-utilization
远非稳定,它几乎总是 0%,并在 80/90% 时飙升,然后一遍又一遍地回到 0%。
我认为这种行为是由于我将数据馈送到网络的方式造成的(我在每个步骤后获取数据,这需要一些时间)。但在实现队列来提供数据并避免步骤之间的延迟后,问题仍然存在(请参阅下面的排队系统)。
任何想法?
batch = 128 # size of the batch
x = tf.placeholder("float32", [None, n_steps, n_input])
y = tf.placeholder("float32", [None, n_classes])
# with a capacity of 100 batches, the bottleneck should not be the data feeding
queue = tf.RandomShuffleQueue(capacity=100*batch,
min_after_dequeue=80*batch,
dtypes=[tf.float32, tf.float32],
shapes=[[n_steps, n_input], [n_classes]])
enqueue_op = queue.enqueue_many([x, y])
X_batch, Y_batch = queue.dequeue_many(batch)
sess = tf.Session()
def load_and_enqueue(data):
while True:
X, Y = data.get_next_batch(batch)
sess.run(enqueue_op, feed_dict={x: X, y: Y})
train_thread = threading.Thread(target=load_and_enqueue, args=(data))
train_thread.daemon = True
train_thread.start()
for _ in xrange(max_iter):
sess.run(train_op)