检查 x
是否是可以传递给许多 TF 操作的 TF-native 类型。
用法
tf.is_tensor(
x
)
参数
-
x
要检查的 python 对象。
返回
-
True
如果x
是 TensorFlow-native 类型。
使用 is_tensor
区分无需任何转换即可被 TensorFlow ops 摄取的类型(例如,tf.Tensor
、tf.SparseTensor
和 tf.RaggedTensor
)与需要在摄取之前转换为张量的类型(例如,numpy ndarray
和 Python 标量)。
例如,在以下代码块中:
if not tf.is_tensor(t):
t = tf.convert_to_tensor(t)
return t.shape, t.dtype
我们在访问它的 shape
和 dtype
之前检查以确保 t
是一个张量(如果不是则转换它)。 (但请注意,并非所有 TensorFlow 原生类型都有 shape 或 dtype;tf.data.Dataset
是 TensorFlow 原生类型的一个示例,它既没有 shape 也没有 dtype。)
相关用法
- Python tf.image.random_brightness用法及代码示例
- Python tf.image.pad_to_bounding_box用法及代码示例
- Python tf.io.gfile.GFile.close用法及代码示例
- Python tf.image.adjust_hue用法及代码示例
- Python tf.image.random_contrast用法及代码示例
- Python tf.image.rot90用法及代码示例
- Python tf.identity_n用法及代码示例
- Python tf.image.random_hue用法及代码示例
- Python tf.io.gfile.join用法及代码示例
- Python tf.io.parse_example用法及代码示例
- Python tf.image.flip_left_right用法及代码示例
- Python tf.image.convert_image_dtype用法及代码示例
- Python tf.image.stateless_random_flip_up_down用法及代码示例
- Python tf.image.random_saturation用法及代码示例
- Python tf.image.extract_glimpse用法及代码示例
- Python tf.image.flip_up_down用法及代码示例
- Python tf.image.crop_to_bounding_box用法及代码示例
- Python tf.image.stateless_random_jpeg_quality用法及代码示例
- Python tf.io.gfile.exists用法及代码示例
- Python tf.image.crop_and_resize用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.is_tensor。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。