Tensorflow重置或清除收集

use*_*206 2 python-3.x tensorflow

在tensorflow中,我发现API tf.add_to_collcetion为集合添加一些值,如下面的代码.

def accuracy_rate(logits, labels):
    correct = tf.nn.in_top_k(logits, labels, 1)
    # Return the accuracy of true entries.
    accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))
    return accuracy 
with tf.Session() as sess:
    logits, labels = ...
    accuracy = accuracy_rate(logits, labels)
    tf.add_to_collection('total_accuracy', sess.run(accuracy))
Run Code Online (Sandbox Code Playgroud)

我在API中找不到的是,如何清除我已经存储在一个集合中的所有值?

Ale*_*sos 5

您可以使用tf.get_collection_ref获取可以清除的集合的可变引用(它只是一个python列表).