def l1_l2_regularizer(weight_l1=1.0, weight_l2=1.0, scope=None):
 def regularizer(tensor):
  with tf.name_scope(scope, 'L1L2Regularizer', [tensor]):
   weight_l1_t = tf.convert_to_tensor(weight_l1, dtype=tensor.dtype.base_dtype, name='weight_l1')
   weight_l2_t = tf.convert_to_tensor(weight_l2, dtype=tensor.dtype.base_dtype, name='weight_l2')
   reg_l1 = tf.multiply(weight_l1_t, tf.reduce_sum(tf.abs(tensor)), name='value_l1')
   reg_l2 = tf.multiply(weight_l2_t, tf.nn.l2_loss(tensor), name='value_l2')
   return tf.add(reg_l1, reg_l2, name='value')
 return regularizer

def l1_l2_regularizer ( weight_l1 = 1.0 , weight_l2 = 1.0 , scope = None ) : def regularizer ( tensor ) : with tf . name_scope ( scope , 'L1L2Regularizer' , [ tensor ] ) : weight_l1_t = tf . convert_to_tensor ( weight_l1 , dtype = tensor . dtype . base_dtype , name = 'weight_l1' ) weight_l2_t = tf . convert_to_tensor ( weight_l2 , dtype = tensor . dtype . base_dtype , name = 'weight_l2' ) reg_l1 = tf . multiply ( weight_l1_t , tf . reduce_sum ( tf . abs ( tensor ) ) , name = 'value_l1' ) reg_l2 = tf . multiply ( weight_l2_t , tf . nn . l2_loss ( tensor ) , name = 'value_l2' ) return tf . add ( reg_l1 , reg_l2 , name = 'value' ) return regularizer
define a l1l2 regularizer .