Spec-Zone.ru › TensorFlow 2.9

tf.compat.dimension_at_index

View source on GitHub

Утилита совместимости, необходимая для поддержки как поведения V1, так и V2 в TF.

Просмотр псевдонимов

Псевдонимы совместимости для миграции

См. руководство по миграции для получения более подробной информации.

tf.compat.v1.compat.dimension_at_index, tf.compat.v1.dimension_at_index

tf.compat.dimension_at_index(
    shape, index
)

До выхода TF 2.0 нам необходимо, чтобы устаревшее поведение TensorShape сосуществовало с новым поведением. Данная утилита служит мостом между ними.

Если вы хотите получить экземпляр Dimension, соответствующий определенному индексу в экземпляре TensorShape, используйте эту утилиту следующим образом:

# If you had this in your V1 code:
dim = tensor_shape[i]

# Use `dimension_at_index` as direct replacement compatible with both V1 & V2:
dim = dimension_at_index(tensor_shape, i)

# Another possibility would be this, but WARNING: it only works if the
# tensor_shape instance has a defined rank.
dim = tensor_shape.dims[i]  # `dims` may be None if the rank is undefined!

# In native V2 code, we recommend instead being more explicit:
if tensor_shape.rank is None:
  dim = Dimension(None)
else:
  dim = tensor_shape.dims[i]

# Being more explicit will save you from the following trap (present in V1):
# you might do in-place modifications to `dim` and expect them to be reflected
# in `tensor_shape[i]`, but they would not be (as the Dimension object was
# instantiated on the fly.
Аргументы
shape Экземпляр TensorShape.
index Целочисленный индекс.
Возвращаемое значение
Объект dimension.

© 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/versions/r2.9/api_docs/python/tf/compat/dimension_at_index

Spec-Zone.ru

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