本文整理匯總了Python中tensorflow.core.framework.tensor_pb2.TensorProto方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor_pb2.TensorProto方法的具體用法?Python tensor_pb2.TensorProto怎麽用?Python tensor_pb2.TensorProto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.core.framework.tensor_pb2
的用法示例。
在下文中一共展示了tensor_pb2.TensorProto方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ShapeEquals
# 需要導入模塊: from tensorflow.core.framework import tensor_pb2 [as 別名]
# 或者: from tensorflow.core.framework.tensor_pb2 import TensorProto [as 別名]
def ShapeEquals(tensor_proto, shape):
"""Returns True if "tensor_proto" has the given "shape".
Args:
tensor_proto: A TensorProto.
shape: A tensor shape, expressed as a TensorShape, list, or tuple.
Returns:
True if "tensor_proto" has the given "shape", otherwise False.
Raises:
TypeError: If "tensor_proto" is not a TensorProto, or shape is not a
TensorShape, list, or tuple.
"""
if not isinstance(tensor_proto, tensor_pb2.TensorProto):
raise TypeError("tensor_proto is not a tensor_pb2.TensorProto object")
if isinstance(shape, tensor_shape_pb2.TensorShapeProto):
shape = [d.size for d in shape.dim]
elif not isinstance(shape, (list, tuple)):
raise TypeError("shape is not a list or tuple")
tensor_shape_list = [d.size for d in tensor_proto.tensor_shape.dim]
return all(x == y for x, y in zip(tensor_shape_list, shape))
示例2: _prepare_output_as_AppendArrayToTensorProto
# 需要導入模塊: from tensorflow.core.framework import tensor_pb2 [as 別名]
# 或者: from tensorflow.core.framework.tensor_pb2 import TensorProto [as 別名]
def _prepare_output_as_AppendArrayToTensorProto(
inference_output,
model_available_outputs):
response = predict_pb2.PredictResponse()
for response_output_name, model_output_name in \
model_available_outputs.items():
if model_output_name in inference_output:
dtype = dtypes.as_dtype(inference_output[model_output_name].dtype)
output_tensor = tensor_pb2.TensorProto(
dtype=dtype.as_datatype_enum,
tensor_shape=tensor_shape.as_shape(
inference_output[model_output_name].shape).as_proto())
result = inference_output[model_output_name].flatten()
tensor_util._NP_TO_APPEND_FN[dtype.as_numpy_dtype](output_tensor,
result)
response.outputs[response_output_name].CopyFrom(output_tensor)
return response
示例3: _MakeTensor
# 需要導入模塊: from tensorflow.core.framework import tensor_pb2 [as 別名]
# 或者: from tensorflow.core.framework.tensor_pb2 import TensorProto [as 別名]
def _MakeTensor(v, arg_name):
"""Ensure v is a TensorProto."""
if isinstance(v, tensor_pb2.TensorProto):
return v
raise TypeError(
"Don't know how to convert %s to a TensorProto for argument '%s'" %
(repr(v), arg_name))
示例4: _create_const_node
# 需要導入模塊: from tensorflow.core.framework import tensor_pb2 [as 別名]
# 或者: from tensorflow.core.framework.tensor_pb2 import TensorProto [as 別名]
def _create_const_node(self, name, value):
tensor_content = value.tobytes()
dt = tf.as_dtype(value.dtype).as_datatype_enum
tensor_shape = TensorShapeProto(
dim=[TensorShapeProto.Dim(size=s) for s in value.shape])
tensor_proto = TensorProto(tensor_content=tensor_content,
tensor_shape=tensor_shape,
dtype=dt)
node = tf.compat.v1.NodeDef(name=name, op='Const',
attr={'value': tf.compat.v1.AttrValue(tensor=tensor_proto),
'dtype': tf.compat.v1.AttrValue(type=dt)})
return node
示例5: make_const_node
# 需要導入模塊: from tensorflow.core.framework import tensor_pb2 [as 別名]
# 或者: from tensorflow.core.framework.tensor_pb2 import TensorProto [as 別名]
def make_const_node(data: Tensor, name: str = None) -> NodeDef:
"""
Create a TF graph node containing a constant value.
The resulting node is equivalent to using `tf.constant` on the
default graph.
Args:
data: Numpy-array containing the data, shape, and datatype
name: Optional name of the node
Returns:
Graph node for adding to a TF Graph instance
"""
dtype = as_dtype(data.dtype).as_datatype_enum
tensor_content = data.tobytes()
tensor_dim = [TensorShapeProto.Dim(size=size) for size in data.shape]
tensor_shape = TensorShapeProto(dim=tensor_dim)
tensor_proto = TensorProto(tensor_content=tensor_content,
tensor_shape=tensor_shape,
dtype=dtype)
node_def = NodeDef(op='Const', name=name or 'Const',
attr={
'value': AttrValue(tensor=tensor_proto),
'dtype': AttrValue(type=dtype)
})
return node_def
示例6: make_tensor
# 需要導入模塊: from tensorflow.core.framework import tensor_pb2 [as 別名]
# 或者: from tensorflow.core.framework.tensor_pb2 import TensorProto [as 別名]
def make_tensor(v, arg_name):
"""Ensure v is a TensorProto."""
if isinstance(v, tensor_pb2.TensorProto):
return v
elif isinstance(v, six.string_types):
pb = tensor_pb2.TensorProto()
text_format.Merge(v, pb)
return pb
raise TypeError(
"Don't know how to convert %s to a TensorProto for argument '%s'." %
(repr(v), arg_name))
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:13,代碼來源:execute.py