Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow reset or clear collection

In tensorflow, I find the API tf.add_to_collcetion to add some value to collection like code bellow.

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))

What I can't find in the API is that, how can I clear all values that I've already stored in one collection?

like image 824
user6932206 Avatar asked Jan 01 '26 02:01

user6932206


1 Answers

You can use tf.get_collection_ref to get a mutable reference to the collection which you can clear (it's just a python list).

like image 128
Alexandre Passos Avatar answered Jan 05 '26 06:01

Alexandre Passos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!