tff.learning.framework.ModelWeights

Class ModelWeights

Defined in learning/model_utils.py.

A container for the trainable and non-trainable variables of a Model.

Note this does not include the model's local variables.

It may also be used to hold other values that are parallel to these variables, e.g., tensors corresponding to variable values, or updates to model variables.

__new__

@staticmethod
__new__(
    cls,
    trainable,
    non_trainable
)

Properties

trainable

non_trainable

keras_weights

Returns a list of weights in the same order as tf.keras.Model.weights.

(Assuming that this ModelWeights object corresponds to the weights of a keras model).

IMPORTANT: this is not the same order as tf.keras.Model.get_weights(), and hence will not work with tf.keras.Model.set_weights(). Instead, use tff.learning.ModelWeights.assign_weights_to.

Methods

assign_weights_to

assign_weights_to(keras_model)

Assign these TFF model weights to the weights of a tf.keras.Model.

Args:

  • keras_model: the tf.keras.Model object to assign weights to.

from_model

@classmethod
from_model(
    cls,
    model
)

from_tff_value

@classmethod
from_tff_value(
    cls,
    anon_tuple
)