Skip to content

Commit

Permalink
Automated rollback of commit 209c7da. Revert tensorflow#22478.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 222489301
  • Loading branch information
tensorflower-gardener committed Nov 22, 2018
1 parent e679321 commit abcc0bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
10 changes: 0 additions & 10 deletions tensorflow/python/keras/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from tensorflow.python.layers import core as tf_core_layers
from tensorflow.python.ops import nn
from tensorflow.python.ops import rnn_cell
from tensorflow.python.ops import variable_scope
from tensorflow.python.platform import test


Expand Down Expand Up @@ -313,15 +312,6 @@ def test_using_tf_layers_in_keras_functional_model(self):
verbose=0)
self.assertGreater(history.history['val_acc'][-1], 0.7)

def test_regularizers_with_get_variable(self):
# Test case for GitHub issue 22470.
with self.cached_session():
v = variable_scope.get_variable(
'v',
shape=[4, 4],
initializer=keras.initializers.glorot_uniform(),
regularizer=keras.regularizers.l2(0.))


if __name__ == '__main__':
test.main()
15 changes: 6 additions & 9 deletions tensorflow/python/keras/regularizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import six

from tensorflow.python.framework import ops
from tensorflow.python.keras import backend as K
from tensorflow.python.keras.utils.generic_utils import deserialize_keras_object
from tensorflow.python.keras.utils.generic_utils import serialize_keras_object
Expand Down Expand Up @@ -55,14 +54,12 @@ def __init__(self, l1=0., l2=0.): # pylint: disable=redefined-outer-name
self.l2 = K.cast_to_floatx(l2)

def __call__(self, x):
if self.l1 or self.l2:
regularization = ops.convert_to_tensor(0., dtype=K.floatx())
if self.l1:
regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x))
if self.l2:
regularization += math_ops.reduce_sum(self.l2 * math_ops.square(x))
return regularization
return None
regularization = 0.
if self.l1:
regularization += math_ops.reduce_sum(self.l1 * math_ops.abs(x))
if self.l2:
regularization += math_ops.reduce_sum(self.l2 * math_ops.square(x))
return regularization

def get_config(self):
return {'l1': float(self.l1), 'l2': float(self.l2)}
Expand Down

0 comments on commit abcc0bb

Please sign in to comment.