tf.train.TrackableView
Stay organized with collections
Save and categorize content based on your preferences.
Gathers and serializes a trackable view.
tf.train.TrackableView(
root
)
Example usage:
class SimpleModule(tf.Module):
def __init__(self, name=None):
super().__init__(name=name)
self.a_var = tf.Variable(5.0)
self.b_var = tf.Variable(4.0)
self.vars = [tf.Variable(1.0), tf.Variable(2.0)]
root = SimpleModule(name="root")
root.leaf = SimpleModule(name="leaf")
trackable_view = tf.train.TrackableView(root)
Pass root to tf.train.TrackableView.children() to get the dictionary of all
children directly linked to root by name.
>>> trackable_view_children = trackable_view.children(root)
>>> for item in trackable_view_children.items():
... print(item)
('a_var', <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=5.0>)
('b_var', <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=4.0>)
('vars', ListWrapper([<tf.Variable 'Variable:0' shape=() dtype=float32,
numpy=1.0>, <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0>]))
('leaf', ...)
Args |
root
|
A Trackable object whose variables (including the variables of
dependencies, recursively) should be saved. May be a weak reference.
|
Methods
children
View source
@classmethod
children(
obj, save_type=base.SaveType.CHECKPOINT, **kwargs
)
Returns all child trackables attached to obj.
Args |
obj
|
A Trackable object.
|
save_type
|
A string, can be 'savedmodel' or 'checkpoint'.
|
**kwargs
|
kwargs to use when retrieving the object's children.
|
Returns |
Dictionary of all children attached to the object with name to trackable.
|
descendants
View source
descendants()
Returns a list of all nodes from self.root using a breadth first traversal.
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. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.train.TrackableView\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/checkpoint/trackable_view.py#L25-L117) |\n\nGathers and serializes a trackable view. \n\n tf.train.TrackableView(\n root\n )\n\n#### Example usage:\n\n class SimpleModule(tf.Module):\n def __init__(self, name=None):\n super().__init__(name=name)\n self.a_var = tf.Variable(5.0)\n self.b_var = tf.Variable(4.0)\n self.vars = [tf.Variable(1.0), tf.Variable(2.0)]\n\n root = SimpleModule(name=\"root\")\n root.leaf = SimpleModule(name=\"leaf\")\n trackable_view = tf.train.TrackableView(root)\n\nPass root to tf.train.TrackableView.children() to get the dictionary of all\nchildren directly linked to root by name. \n\n \u003e\u003e\u003e trackable_view_children = trackable_view.children(root)\n \u003e\u003e\u003e for item in trackable_view_children.items():\n ... print(item)\n ('a_var', \u003ctf.Variable 'Variable:0' shape=() dtype=float32, numpy=5.0\u003e)\n ('b_var', \u003ctf.Variable 'Variable:0' shape=() dtype=float32, numpy=4.0\u003e)\n ('vars', ListWrapper([\u003ctf.Variable 'Variable:0' shape=() dtype=float32,\n numpy=1.0\u003e, \u003ctf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0\u003e]))\n ('leaf', ...)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|---------------------------------------------------------------------------------------------------------------------------------------|\n| `root` | A `Trackable` object whose variables (including the variables of dependencies, recursively) should be saved. May be a weak reference. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------|---------------|\n| `root` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `children`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/checkpoint/trackable_view.py#L69-L87) \n\n @classmethod\n children(\n obj, save_type=base.SaveType.CHECKPOINT, **kwargs\n )\n\nReturns all child trackables attached to obj.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------|------------------------------------------------------|\n| `obj` | A `Trackable` object. |\n| `save_type` | A string, can be 'savedmodel' or 'checkpoint'. |\n| `**kwargs` | kwargs to use when retrieving the object's children. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| Dictionary of all children attached to the object with name to trackable. ||\n\n\u003cbr /\u003e\n\n### `descendants`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/checkpoint/trackable_view.py#L98-L100) \n\n descendants()\n\nReturns a list of all nodes from self.root using a breadth first traversal."]]