Registration is open for TensorFlow Dev Summit 2020 Learn more

tf.keras.regularizers.L1L2

TensorFlow 1 version View source on GitHub

Class L1L2

A regularizer that applies both L1 and L2 regularization penalties.

Inherits From: Regularizer

The L1 regularization penalty is computed as:

\(\ell_1\,\,penalty =\ell_1\sum_{i=0}^n|x_i|\)

The L2 regularization penalty is computed as

\(\ell_2\,\,penalty =\ell_2\sum_{i=0}^nx_i^2\)

Attributes:

  • l1: Float; L1 regularization factor.
  • l2: Float; L2 regularization factor.

__init__

View source

__init__(
    l1=0.0,
    l2=0.0
)

Initialize self. See help(type(self)) for accurate signature.

Methods

__call__

View source

__call__(x)

Compute a regularization penalty from an input tensor.

from_config

View source

@classmethod
from_config(
    cls,
    config
)

Creates a regularizer from its config.

This method is the reverse of get_config, capable of instantiating the same regularizer from the config dictionary.

This method is used by Keras model_to_estimator, saving and loading models to HDF5 formats, Keras model cloning, some visualization utilities, and exporting models to and from JSON.

Arguments:

  • config: A Python dictionary, typically the output of get_config.

Returns:

A regularizer instance.

get_config

View source

get_config()

Returns the config of the regularizer.

An regularizer config is a Python dictionary (serializable) containing all configuration parameters of the regularizer. The same regularizer can be reinstantiated later (without any saved state) from this configuration.

This method is optional if you are just training and executing models, exporting to and from SavedModels, or using weight checkpoints.

This method is required for Keras model_to_estimator, saving and loading models to HDF5 formats, Keras model cloning, some visualization utilities, and exporting models to and from JSON.

Returns:

Python dictionary.