tf.compat.v1.executing_eagerly_outside_functions
Возвращает True, если выполнение происходит в режиме eager, даже если внутри функции графа.
tf.compat.v1.executing_eagerly_outside_functions()
Эта функция проверит внешний контекст программы и определит, находится ли она в режиме eager. Она полезна для сравнения с tf.executing_eagerly(), которая проверяет текущий контекст и вернёт False внутри тела tf.function. Её можно использовать для создания библиотек, которые ведут себя по-разному в режиме eager и в режиме сессии v1 (устаревший).
Пример:
tf.compat.v1.enable_eager_execution() @tf.function def func(): # A function constructs TensorFlow graphs, it does not execute eagerly, # but the outer most context is still eager. assert not tf.executing_eagerly() return tf.compat.v1.executing_eagerly_outside_functions() func() <tf.Tensor: shape=(), dtype=bool, numpy=True>
| Возвращаемое значение | |
|---|---|
| boolean, является ли внешний контекст в режиме eager. |
© 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/v1/executing_eagerly_outside_functions