tf.make_tensor_proto
Stay organized with collections
Save and categorize content based on your preferences.
Create a TensorProto.
tf.make_tensor_proto(
values, dtype=None, shape=None, verify_shape=False, allow_broadcast=False
)
In TensorFlow 2.0, representing tensors as protos should no longer be a
common workflow. That said, this utility function is still useful for
generating TF Serving request protos:
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
accepts "values" of a python scalar, a python list, a
numpy ndarray, or a numpy scalar.
If "values" is a python scalar or a python list, make_tensor_proto
first convert it to numpy ndarray. If dtype is None, the
conversion tries its best to infer the right numpy data
type. Otherwise, the resulting numpy array has a compatible data
type with the given dtype.
In either case above, the numpy ndarray (either the caller provided
or the auto-converted) must have the compatible type with dtype.
make_tensor_proto
then converts the numpy array to a tensor proto.
If "shape" is None, the resulting tensor proto represents the numpy
array precisely.
Otherwise, "shape" specifies the tensor's shape and the numpy array
can not have more elements than what "shape" specifies.
Args |
values
|
Values to put in the TensorProto.
|
dtype
|
Optional tensor_pb2 DataType value.
|
shape
|
List of integers representing the dimensions of tensor.
|
verify_shape
|
Boolean that enables verification of a shape of values.
|
allow_broadcast
|
Boolean that enables allowing scalars and 1 length vector
broadcasting. Cannot be true when verify_shape is true.
|
Returns |
A TensorProto . Depending on the type, it may contain data in the
"tensor_content" attribute, which is not directly useful to Python programs.
To access the values you should convert the proto back to a numpy ndarray
with tf.make_ndarray(proto) .
If values is a TensorProto , it is immediately returned; dtype and
shape are ignored.
|
Raises |
TypeError
|
if unsupported types are provided.
|
ValueError
|
if arguments have inappropriate values or if verify_shape is
True and shape of values is not equals to a shape from the argument.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.make_tensor_proto\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/framework/tensor_util.py#L425-L629) |\n\nCreate a TensorProto.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.make_tensor_proto`](https://www.tensorflow.org/api_docs/python/tf/make_tensor_proto)\n\n\u003cbr /\u003e\n\n tf.make_tensor_proto(\n values, dtype=None, shape=None, verify_shape=False, allow_broadcast=False\n )\n\nIn TensorFlow 2.0, representing tensors as protos should no longer be a\ncommon workflow. That said, this utility function is still useful for\ngenerating TF Serving request protos: \n\n request = tensorflow_serving.apis.predict_pb2.PredictRequest()\n request.model_spec.name = \"my_model\"\n request.model_spec.signature_name = \"serving_default\"\n request.inputs[\"images\"].CopyFrom(tf.make_tensor_proto(X_new))\n\n`make_tensor_proto` accepts \"values\" of a python scalar, a python list, a\nnumpy ndarray, or a numpy scalar.\n\nIf \"values\" is a python scalar or a python list, make_tensor_proto\nfirst convert it to numpy ndarray. If dtype is None, the\nconversion tries its best to infer the right numpy data\ntype. Otherwise, the resulting numpy array has a compatible data\ntype with the given dtype.\n\nIn either case above, the numpy ndarray (either the caller provided\nor the auto-converted) must have the compatible type with dtype.\n\n`make_tensor_proto` then converts the numpy array to a tensor proto.\n\nIf \"shape\" is None, the resulting tensor proto represents the numpy\narray precisely.\n\nOtherwise, \"shape\" specifies the tensor's shape and the numpy array\ncan not have more elements than what \"shape\" specifies.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|-------------------------------------------------------------------------------------------------------------------|\n| `values` | Values to put in the TensorProto. |\n| `dtype` | Optional tensor_pb2 DataType value. |\n| `shape` | List of integers representing the dimensions of tensor. |\n| `verify_shape` | Boolean that enables verification of a shape of values. |\n| `allow_broadcast` | Boolean that enables allowing scalars and 1 length vector broadcasting. Cannot be true when verify_shape is true. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `TensorProto`. Depending on the type, it may contain data in the \"tensor_content\" attribute, which is not directly useful to Python programs. To access the values you should convert the proto back to a numpy ndarray with [`tf.make_ndarray(proto)`](../tf/make_ndarray). \u003cbr /\u003e If `values` is a `TensorProto`, it is immediately returned; `dtype` and `shape` are ignored. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------------------------------------------------------------------------------|\n| `TypeError` | if unsupported types are provided. |\n| `ValueError` | if arguments have inappropriate values or if verify_shape is True and shape of values is not equals to a shape from the argument. |\n\n\u003cbr /\u003e"]]