Update to avoid useless node in the graph based on review
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
7efb78e55c
commit
1994b259d9
@ -55,12 +55,14 @@ class L1L2(Regularizer):
|
|||||||
self.l2 = K.cast_to_floatx(l2)
|
self.l2 = K.cast_to_floatx(l2)
|
||||||
|
|
||||||
def __call__(self, x):
|
def __call__(self, x):
|
||||||
|
if self.l1 or self.l2:
|
||||||
regularization = ops.convert_to_tensor(0., dtype=K.floatx())
|
regularization = ops.convert_to_tensor(0., dtype=K.floatx())
|
||||||
if self.l1:
|
if self.l1:
|
||||||
regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x))
|
regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x))
|
||||||
if self.l2:
|
if self.l2:
|
||||||
regularization += math_ops.reduce_sum(self.l2 * math_ops.square(x))
|
regularization += math_ops.reduce_sum(self.l2 * math_ops.square(x))
|
||||||
return regularization
|
return regularization
|
||||||
|
return None
|
||||||
|
|
||||||
def get_config(self):
|
def get_config(self):
|
||||||
return {'l1': float(self.l1), 'l2': float(self.l2)}
|
return {'l1': float(self.l1), 'l2': float(self.l2)}
|
||||||
|
Loading…
Reference in New Issue
Block a user