TensorFlow函数(九)tf.add_to_collection()、tf.get_collection() 和 tf.add_n()

时间:2023-08-10 22:18:32

tf.add_to_collection(name, value)

此函数将元素添加到列表中

参数:

  • name:列表名。如果不存在,创建一个新的列表
  • value:元素

tf.get_collection(name)

此函数获取列表

参数:

  • name:列表名

tf.add_n(inputs)

此函数将元素相加并返回

注意:元素类型必须一致,否者报错

 tf.add_to_collection('losses', regularizer(weights))
tf.add_n(tf.get_collection('losses'))