tff.learning.models.functional_model_from_keras

Converts a tf.keras.Model to a tff.learning.models.FunctionalModel.

This method doesn't support loss functions scaled by sample weights at the current state. Keras models with non-None sample weights will fail because sample weights aren't supported in model serialization and deserialization.

keras_model A tf.keras.Model object, should be uncompiled. If compiled, the metrics, optimizer, and loss function will be ignored. Note: models that have multiple outputs will send all outputs to the loss_fn.
loss_fn A tf.keras.losses.Loss object.
input_spec A structure of tf.TensorSpec defining the input to the model.
metrics_constructor An optional callable that must be compatible with tff.learning.metrics.create_functional_metric_fns.

A tff.learning.models.FunctionalModel.

KerasFunctionalModelError If the following conditions: 1) the Keras model contains a batch normalization layer, 2) the Keras model is with non-trainable variable, 3) error occurs when converting the Keras model, 4) the Keras model shares variable across layers, 5) the FunctionalModel is used outside of a tff.tf_computation decorated callable or a graph context,

6) the Keras model contains a loss function with non-None sample weights.