tfl.pwl_calibration_layer.HessianRegularizer

View source on GitHub

Class HessianRegularizer

Hessian regularizer for PWL calibration layer.

Calibrator hessian regularizer penalizes the change in slopes of linear pieces. It is define to be:

l1 * ||nonlinearity||_1 + l2 * ||nonlinearity||_2^2

where nonlinearity is:

2 * output_keypoints[1:end-1] - output_keypoints[0:end-2] - output_keypoints[2:end].

This regularizer is zero when the output_keypoints form a linear function of the index (and not necessarily linear in input values, e.g. when using non-uniform input keypoints).

Attributes:

  • All __init__ arguments.

__init__

View source

__init__(
    l1=0.0,
    l2=0.0,
    is_cyclic=False
)

Initializes an instance of HessianRegularizer.

Args:

  • l1: l1 regularization amount as float.
  • l2: l2 regularization amount as float.
  • is_cyclic: Whether the first and last keypoints should take the same output value.

Methods

__call__

View source

__call__(x)

Returns regularization loss.

Args:

  • x: Tensor of shape: (k, units) which represents weights of PWL calibration layer. First row of weights is bias term. All remaining represent delta in y-value compare to previous point (segment heights).

from_config

@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()

Standard Keras config for serialization.