Spec-Zone.ru › TensorFlow

tf.keras.tree.pack_sequence_as

Возвращает заданную сплющенную последовательность, упакованную в заданную структуру.

tf.keras.tree.pack_sequence_as(
    structure, flat_sequence, sequence_fn=None
)

Если structure является атомом, то flat_sequence должна быть списком из одного элемента; в этом случае значение возврата — flat_sequence[0].

Если structure является или содержит экземпляр словаря, ключи будут отсортированы, чтобы упаковать сплющенную последовательность в детерминированном порядке. Это также верно для экземпляров OrderedDict: учитывается их порядок следования. Такая же конвенция используется в flatten. Это правильно упаковывает словари и OrderedDicts после их сплющивания или наоборот.

Словари с несортируемыми ключами не могут быть сплющены.

Примеры:

structure = {"key3": "", "key1": "", "key2": ""}
flat_sequence = ["value1", "value2", "value3"]
keras.tree.pack_sequence_as(structure, flat_sequence)
{"key3": "value3", "key1": "value1", "key2": "value2"}
structure = (("a", "b"), ("c", "d", "e"), "f")
flat_sequence = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
keras.tree.pack_sequence_as(structure, flat_sequence)
((1.0, 2.0), (3.0, 4.0, 5.0), 6.0)
structure = {"key3": {"c": ("alpha", "beta"), "a": ("gamma")},
"key1": {"e": "val1", "d": "val2"} }
flat_sequence = ["val2", "val1", 3.0, 1.0, 2.0]
keras.tree.pack_sequence_as(structure, flat_sequence)
{'key3': {'c': (1.0, 2.0), 'a': 3.0}, 'key1': {'e': 'val1', 'd': 'val2'} }
structure = ["a"]
flat_sequence = [np.array([[1, 2], [3, 4]])]
keras.tree.pack_sequence_as(structure, flat_sequence)
[array([[1, 2],
   [3, 4]])]
structure = ["a"]
flat_sequence = [keras.ops.ones([2, 2])]
keras.tree.pack_sequence_as(structure, flat_sequence)
[array([[1., 1.],
   [1., 1.]]]
Аргументы
structure Вложенная структура произвольной сложности.
flat_sequence Сплющенная последовательность для упаковки.
sequence_fn По умолчанию равно _sequence_like.
Возвращаемое значение
flat_sequence преобразован в структуру с той же рекурсивной структурой, что и structure.

© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/keras/tree/pack_sequence_as

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API