使用TensorFlow Profiler测量GPU内存使用情况

时间:2018-10-17 22:22:58

标签: tensorflow

是否有一种方法可以使用TensorFlow事件探查器正确测量tf.Estimator模型的GPU使用率?我遵循了文档:

g = tf.Graph()
sess = tf.Session(graph=g)
run_meta = tf.RunMetadata()

time_and_memory_args = tf.profiler.ProfileOptionBuilder.time_and_memory()

with g.as_default():
    data_shape = [BATCH_SIZE] + [3, 224, 224]
    in_plh = tf.placeholder(tf.float32, data_shape)

    model = some_model(in_plh, args=model_args, training=True)
    images = np.random.rand(BATCH_SIZE, 3, 224, 224)

    sess.run(tf.global_variables_initializer())
    sess.run(model, feed_dict={in_plh: images})

    time_and_memory = tf.profiler.profile(g, run_meta=run_meta, cmd='op',
                                          options=time_and_memory_args) 

    if time_and_memory is not None:
        print('Total requested bytes:', time_and_memory.total_requested_bytes)

但是打印结果始终为0。

0 个答案:

没有答案