def sum_regularizer(regularizer_list):
"""Returns a function that applies the sum of multiple regularizers.
Args:
regularizer_list: A list of regularizers to apply.
Returns:
A function with signature `sum_reg(weights, name=None)` that applies the
sum of all the input regularizers.
"""
regularizer_list = [reg for reg in regularizer_list if reg is not None]
if not regularizer_list:
return None
def sum_reg(weights, name=None):
"""Applies the sum of all the input regularizers."""
with ops.op_scope([weights], name, 'sum_regularizer') as scope:
regularizer_tensors = [reg(weights) for reg in regularizer_list]
return math_ops.add_n(regularizer_tensors, name=scope)
return sum_reg
评论列表
文章目录