檢查 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。