def main(_) -> None: with test_utils.model_type_scope('functional'): model = test_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)
def context_managers(self, kwargs): model_type = kwargs.pop('model_type', None) if model_type in KERAS_MODEL_TYPES: return [test_utils.model_type_scope(model_type)] else: return []
def _test_subclass_model_type(f, test_or_class, *args, **kwargs): with test_utils.model_type_scope('subclass'): f(test_or_class, *args, **kwargs)
def _test_sequential_model_type(f, test_or_class, *args, **kwargs): with test_utils.model_type_scope('sequential'): f(test_or_class, *args, **kwargs)
def _test_functional_model_type(f, test_or_class, *args, **kwargs): with test_utils.model_type_scope('functional'): f(test_or_class, *args, **kwargs)