edo1z blog

プログラミングなどに関するブログです

TensorFlow - tf.add_to_collection

tf.add_to_collection(name, value)は、tf.Graph.add_to_collection(name, value)のラッパーだそうです。

引数

  • name: The key for the collection. The GraphKeys class contains many standard names for collections.
  • value: The value to add to the collection.

すごい単純だな。

import tensorflow as tf

tf.add_to_collection('hoge', 12)
tf.add_to_collection('hoge', 25)
hoge = tf.get_collection('hoge')
add = tf.add_n(hoge)

with tf.Session() as sess:
    print(sess.run(add))

結果

37