本文整理匯總了Python中onnx.numpy_helper方法的典型用法代碼示例。如果您正苦於以下問題:Python onnx.numpy_helper方法的具體用法?Python onnx.numpy_helper怎麽用?Python onnx.numpy_helper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類onnx
的用法示例。
在下文中一共展示了onnx.numpy_helper方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _onnx_initializer_to_input_dict_items
# 需要導入模塊: import onnx [as 別名]
# 或者: from onnx import numpy_helper [as 別名]
def _onnx_initializer_to_input_dict_items(initializer):
""" Convert ONNX graph initializer to input dict items.
:param initializer: ONNX graph initializer, list of TensorProto.
:return: List of input dict items.
"""
def tensor2list(onnx_tensor):
# Use the onnx.numpy_helper because the data may be raw
return numpy_helper.to_array(onnx_tensor).flatten().tolist()
return [(init.name,
tf.constant(
tensor2list(init),
shape=init.dims,
dtype=onnx2tf(init.data_type)))
for init in initializer]
示例2: to_array
# 需要導入模塊: import onnx [as 別名]
# 或者: from onnx import numpy_helper [as 別名]
def to_array(self): # type: () -> numpy.ndarray
"""Get the value of this tensor as a Numpy array."""
return onnx.numpy_helper.to_array(self._proto)
示例3: onnx_tensor_to_list
# 需要導入模塊: import onnx [as 別名]
# 或者: from onnx import numpy_helper [as 別名]
def onnx_tensor_to_list(tensor):
return onnx.numpy_helper.to_array(tensor).flatten().tolist()
示例4: get_numpy
# 需要導入模塊: import onnx [as 別名]
# 或者: from onnx import numpy_helper [as 別名]
def get_numpy(tensor_proto):
"""Grab data in TensorProto and convert to numpy array."""
try:
from onnx.numpy_helper import to_array
except ImportError as e:
raise ImportError(
"Unable to import onnx which is required {}".format(e))
return to_array(tensor_proto)