Пример #1
0
def test_activity_regularization():
    layer = layers.ActivityRegularization(l1=0.01, l2=0.01)

    # test in functional API
    x = layers.Input(shape=(3,))
    z = layers.Dense(2)(x)
    y = layer(z)
    model = Model(x, y)
    model.compile('rmsprop', 'mse')

    model.predict(np.random.random((2, 3)))

    # test serialization
    model_config = model.get_config()
    model = Model.from_config(model_config)
    model.compile('rmsprop', 'mse')
Пример #2
0
 def test_activity_regularization(self):
   x = Normal(loc=tf.zeros([100, 10, 5]), scale=tf.ones([100, 10, 5]))
   y = layers.ActivityRegularization(l1=0.1)(x.value())
Пример #3
0
 def __init__(self):
     super().__init__()
     self.loss_layer = layers.ActivityRegularization(l2=0.001)
     self.add_weight(shape=(1, ), regularizer="l2")
Пример #4
0
 def __init__(self):
   super(LayerWithSharedNestedLossLayer, self).__init__()
   self.loss_layer = layers.ActivityRegularization(l2=0.001)
   self.add_weight(shape=(1,), regularizer='l2')
Пример #5
0
 def test_activity_regularization(self):
     x = Normal(mu=tf.zeros([100, 10, 5]), sigma=tf.ones([100, 10, 5]))
     y = layers.ActivityRegularization(l1=0.1)(x)