Ejemplo n.º 1
0
def main(_) -> None:
    with testing_utils.model_type_scope('functional'):
        model = testing_utils.get_small_mlp(1, 4, input_dim=3)
        model.layers[-1].activity_regularizer = regularizers.get('l2')
        model.activity_regularizer = regularizers.get('l2')
        model.compile(loss='mse', optimizer='rmsprop')

        def callable_loss():
            return tf.reduce_sum(model.weights[0])

        model.add_loss(callable_loss)

        print(f'_____Writing saved model to: {FLAGS.output_path}')
        model.save(FLAGS.output_path)
Ejemplo n.º 2
0
def _test_sequential_model_type(f, test_or_class, *args, **kwargs):
    with testing_utils.model_type_scope('sequential'):
        f(test_or_class, *args, **kwargs)
Ejemplo n.º 3
0
def _test_functional_model_type(f, test_or_class, *args, **kwargs):
    with testing_utils.model_type_scope('functional'):
        f(test_or_class, *args, **kwargs)
Ejemplo n.º 4
0
def _test_subclass_model_type(f, test_or_class, *args, **kwargs):
    with testing_utils.model_type_scope('subclass'):
        f(test_or_class, *args, **kwargs)
Ejemplo n.º 5
0
 def context_managers(self, kwargs):
     model_type = kwargs.pop('model_type', None)
     if model_type in KERAS_MODEL_TYPES:
         return [testing_utils.model_type_scope(model_type)]
     else:
         return []