tff.learning.models.ModelWeights
Stay organized with collections
Save and categorize content based on your preferences.
A container for the trainable and non-trainable variables of a Model
.
tff.learning.models.ModelWeights(
trainable, non_trainable
)
Used in the notebooks
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.
Attributes |
trainable
|
A namedtuple alias for field number 0
|
non_trainable
|
A namedtuple alias for field number 1
|
Methods
assign_weights_to
View source
assign_weights_to(
model: Union[tff.learning.models.VariableModel
, tf.keras.Model]
) -> None
Assign these TFF model weights to the weights of a model.
convert_variables_to_arrays
View source
convert_variables_to_arrays() -> 'ModelWeights'
Converts any internal tf.Variable
s to numpy arrays.
from_model
View source
@classmethod
from_model(
model
)
from_tff_result
View source
@classmethod
from_tff_result(
struct
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.learning.models.ModelWeights\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nA container for the trainable and non-trainable variables of a `Model`. \n\n tff.learning.models.ModelWeights(\n trainable, non_trainable\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Building Your Own Federated Learning Algorithm](https://www.tensorflow.org/federated/tutorials/building_your_own_federated_learning_algorithm) - [Composing Learning Algorithms](https://www.tensorflow.org/federated/tutorials/composing_learning_algorithms) - [Federated Learning for Text Generation](https://www.tensorflow.org/federated/tutorials/federated_learning_for_text_generation) - [Random noise generation in TFF](https://www.tensorflow.org/federated/tutorials/random_noise_generation) |\n\nNote this does not include the model's local variables.\n\nIt may also be used to hold other values that are parallel to these variables,\ne.g., tensors corresponding to variable values, or updates to model variables.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-----------------|-----------------------------------------|\n| `trainable` | A `namedtuple` alias for field number 0 |\n| `non_trainable` | A `namedtuple` alias for field number 1 |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `assign_weights_to`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n assign_weights_to(\n model: Union[../../../tff/learning/models/VariableModel, tf.keras.Model]\n ) -\u003e None\n\nAssign these TFF model weights to the weights of a model.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `model` | A [`tf.keras.Model`](https://www.tensorflow.org/api_docs/python/tf/keras/Model) or [`tff.learning.models.VariableModel`](../../../tff/learning/models/VariableModel) instance to assign the weights to. |\n\n\u003cbr /\u003e\n\n### `convert_variables_to_arrays`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n convert_variables_to_arrays() -\u003e 'ModelWeights'\n\nConverts any internal [`tf.Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable)s to numpy arrays.\n\n### `from_model`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n @classmethod\n from_model(\n model\n )\n\n### `from_tff_result`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n @classmethod\n from_tff_result(\n struct\n )"]]