當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.type_spec_from_value用法及代碼示例

返回表示給定 valuetf.TypeSpec

用法

tf.type_spec_from_value(
    value
) -> tf.TypeSpec

參數

返回

  • value 兼容的 TypeSpec

拋出

  • TypeError 如果無法為 value 構建 TypeSpec,因為它的類型不受支持。

例子:

tf.type_spec_from_value(tf.constant([1, 2, 3]))
TensorSpec(shape=(3,), dtype=tf.int32, name=None)
tf.type_spec_from_value(np.array([4.0, 5.0], np.float64))
TensorSpec(shape=(2,), dtype=tf.float64, name=None)
tf.type_spec_from_value(tf.ragged.constant([[1, 2], [3, 4, 5]]))
RaggedTensorSpec(TensorShape([2, None]), tf.int32, 1, tf.int64)
example_input = tf.ragged.constant([[1, 2], [3]])
@tf.function(input_signature=[tf.type_spec_from_value(example_input)])
def f(x):
  return tf.reduce_sum(x, axis=1)

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.type_spec_from_value。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。