Spec-Zone.ru › TensorFlow 2.9

tf.debugging.assert_type

Просмотреть исходный код на GitHub

Утверждает, что данное Tensor имеет указанный тип.

tf.debugging.assert_type(
    tensor, tf_type, message=None, name=None
)

Это всегда можно проверить статически, поэтому этот метод ничего не возвращает.

Пример:

a = tf.Variable(1.0)
tf.debugging.assert_type(a, tf_type= tf.float32)
b = tf.constant(21)
tf.debugging.assert_type(b, tf_type=tf.bool)
Traceback (most recent call last):

TypeError: ...
c = tf.SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2],
 dense_shape=[3, 4])
tf.debugging.assert_type(c, tf_type= tf.int32)
Аргументы
tensor A Tensor, SparseTensor или tf.Variable .
tf_type Тип TensorFlow (dtypes.float32, tf.int64, dtypes.bool и т.д.).
message Строка для добавления в сообщение по умолчанию.
name Имя этой операции. По умолчанию "assert_type"
Возбуждает исключения
TypeError Если тип данных тензора не соответствует tf_type.

© 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/debugging/assert_type

Spec-Zone.ru

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