tf.keras.tree.assert_same_structure  |  TensorFlow v2.16.1 (original) (raw)

tf.keras.tree.assert_same_structure

Stay organized with collections Save and categorize content based on your preferences.

Asserts that two structures are nested in the same way.

tf.keras.tree.assert_same_structure(
    a, b, check_types=True
)

Note that namedtuples with identical name and fields will not be considered as same structures even check_types=False.

Examples:

keras.tree.assert_same_structure([(0, 1)], [(2, 3)])

Foo = collections.namedtuple('Foo', ['a', 'b']) AlsoFoo = collections.namedtuple('Foo', ['a', 'b']) keras.tree.assert_same_structure(Foo(0, 1), Foo(2, 3)) keras.tree.assert_same_structure(Foo(0, 1), AlsoFoo(2, 3)) Traceback (most recent call last): ValueError: a and b don't have the same structure.

Args
a an arbitrarily nested structure.
b an arbitrarily nested structure.
check_types if True (default) types of leaves are checked as well.

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-06-07 UTC.