tf.add_to_collection(‘list_name’, element):把变量element放入一个名为list_name的集合中,如果有多个变量放入集合中,输出为一个列表
例如:
tf.add_to_collection('losses', regularizer(fc1_weights))
tf.add_to_collection('losses', regularizer(fc2_weights))
那么在集合losses中就两个变量,[fc1_weights,fc2_weights]
tf.get_collection(‘list_name’):得到集合名list_name的列表
例如:
tf.get_collection(‘losses’) 输出为[fc1_weights,fc2_weights]
tf.add_n(list):将集合名为list的列表中的元素相加
例如:tf.add_n(tf.get_collection(‘losses’))
fc1_weights+fc2_weights