tf.add_to_collection() tf.get_collection() tf.add_n()
tf.add_to_collection: the variables into a set, a list of the many variables into tf.get_collection: Remove all the variables from a binding, the list is a tf.add_n: a list of things are combined sequentially example: Import tensorflow TF AS; Import numpy AS NP; Import matplotlib.pyplot AS PLT; V1 = tf.get_variable (name = 'V1', Shape = [. 1], initializer of tf.constant_initializer = (0)) tf.add_to_collection ( 'Loss', V1) V2 = tf.get_variable (name = 'V2', Shape = [. 1], = tf.constant_initializer initializer of (2)) tf.add_to_collection ( 'Loss', V2) with tf.Session () AS Sess: Sess. RUN (tf.initialize_all_variables ()) Print tf.get_collection ( 'Loss') Print sess.run (tf.add_n (tf.get_collection ( 'Loss'))) output: [<tensorflow.python.ops.variables.Variable object at 0x7f6b5d700c50>, <tensorflow.python.ops.variables.Variable object at 0x7f6b5d700c90>] [ 2.]