創建一個 TensorProto。
用法
tf.make_tensor_proto(
values, dtype=None, shape=None, verify_shape=False, allow_broadcast=False
)
參數
-
values
放入 TensorProto 的值。 -
dtype
可選的tensor_pb2 數據類型值。 -
shape
表示張量維度的整數列表。 -
verify_shape
用於驗證值形狀的布爾值。 -
allow_broadcast
允許標量和 1 長度矢量廣播的布爾值。當verify_shape 為真時不能為真。
返回
-
A
TensorProto
.根據類型,它可能包含 "tensor_content" 屬性中的數據,這對 Python 程序沒有直接用處。要訪問這些值,您應該將 proto 轉換回 numpy ndarraytf.make_ndarray.如果
values
是TensorProto
,則立即返回;dtype
和shape
被忽略。
拋出
-
TypeError
如果提供了不支持的類型。 -
ValueError
如果參數具有不適當的值,或者如果 verify_shape 為 True 並且值的形狀不等於參數中的形狀。
在 TensorFlow 2.0 中,將張量表示為 protos 應該不再是常見的工作流程。也就是說,這個實用函數對於生成 TF Serving 請求原型仍然很有用:
request = tensorflow_serving.apis.predict_pb2.PredictRequest()
request.model_spec.name = "my_model"
request.model_spec.signature_name = "serving_default"
request.inputs["images"].CopyFrom(tf.make_tensor_proto(X_new))
make_tensor_proto
接受 python 標量、python 列表、numpy ndarray 或 numpy 標量的 "values"。
如果"values"是python標量或者python列表,make_tensor_proto先轉換成numpy ndarray。如果 dtype 為 None,則轉換會盡力推斷正確的 numpy 數據類型。否則,生成的 numpy 數組具有與給定 dtype 兼容的數據類型。
在上述任何一種情況下,numpy ndarray(提供的調用者或auto-converted)必須具有與 dtype 兼容的類型。
make_tensor_proto
然後將 numpy 數組轉換為張量原型。
如果 "shape" 為 None,則生成的張量原型精確地表示 numpy 數組。
否則,"shape" 指定張量的形狀,numpy 數組的元素不能多於 "shape" 指定的元素。
相關用法
- Python tf.make_ndarray用法及代碼示例
- Python tf.math.special.fresnel_cos用法及代碼示例
- Python tf.math.polyval用法及代碼示例
- Python tf.math.is_finite用法及代碼示例
- Python tf.math.special.bessel_k0e用法及代碼示例
- Python tf.math.acosh用法及代碼示例
- Python tf.math.invert_permutation用法及代碼示例
- Python tf.math.segment_prod用法及代碼示例
- Python tf.math.bincount用法及代碼示例
- Python tf.math.bessel_i0e用法及代碼示例
- Python tf.math.unsorted_segment_min用法及代碼示例
- Python tf.math.conj用法及代碼示例
- Python tf.math.scalar_mul用法及代碼示例
- Python tf.math.zero_fraction用法及代碼示例
- Python tf.math.reduce_max用法及代碼示例
- Python tf.math.special.fresnel_sin用法及代碼示例
- Python tf.math.segment_mean用法及代碼示例
- Python tf.math.xlog1py用法及代碼示例
- Python tf.math.less_equal用法及代碼示例
- Python tf.math.reduce_min用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.make_tensor_proto。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。