本文整理汇总了Python中onnx.ValueInfoProto方法的典型用法代码示例。如果您正苦于以下问题:Python onnx.ValueInfoProto方法的具体用法?Python onnx.ValueInfoProto怎么用?Python onnx.ValueInfoProto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onnx
的用法示例。
在下文中一共展示了onnx.ValueInfoProto方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _extract_value_info
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _extract_value_info(arr, name):
if isinstance(arr, list):
assert arr
assert not isinstance(arr[0], list)
value_info_proto = onnx.ValueInfoProto()
value_info_proto.name = name
sequence_type_proto = value_info_proto.type.sequence_type
nested = _extract_value_info(arr[0], name)
tensor_type = sequence_type_proto.elem_type.tensor_type
tensor_type.CopyFrom(nested.type.tensor_type)
return value_info_proto
else:
return onnx.helper.make_tensor_value_info(
name=name,
elem_type=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[arr.dtype],
shape=arr.shape)
示例2: _assert_inferred
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _assert_inferred(self, graph, vis): # type: (GraphProto, List[ValueInfoProto]) -> None
names_in_vis = set(x.name for x in vis)
vis = list(x for x in graph.value_info if x.name not in names_in_vis) + vis
inferred_model = self._inferred(graph)
inferred_vis = list(inferred_model.graph.value_info)
vis = list(sorted(vis, key=lambda x: x.name))
inferred_vis = list(sorted(inferred_vis, key=lambda x: x.name))
if vis == inferred_vis:
return
# otherwise some custom logic to give a nicer diff
vis_names = set(x.name for x in vis)
inferred_vis_names = set(x.name for x in inferred_vis)
assert vis_names == inferred_vis_names, (vis_names, inferred_vis_names)
for vi, inferred_vi in zip(vis, inferred_vis):
assert vi == inferred_vi, '\n%s\n%s\n' % (vi, inferred_vi)
assert False
示例3: __init__
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def __init__(self, value):
if isinstance(value, Value):
self.const_value = value.const_value
value = value.value
else:
self.const_value = None
self.value = value
self.is_py = not isinstance(self.value, onnx.ValueInfoProto)
if not self.is_py:
assert self.is_tensor() or self.is_sequence()
assert not (self.is_tensor() and self.is_sequence())
示例4: copy
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def copy(self, env: 'utils.Env', name=None) -> 'Value':
self.to_value_info(env)
vi = self.value
nvi = onnx.ValueInfoProto()
if self.is_tensor():
nvi.name = utils.gen_id(name, 'T')
else:
assert self.is_sequence(), self
nvi.name = utils.gen_id(name, 'S')
nvi.type.CopyFrom(vi.type)
return Value(nvi)
示例5: to_value_info
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def to_value_info(self, env: 'utils.Env') -> onnx.ValueInfoProto:
if self.is_py:
if isinstance(self.value, collections.Iterable):
return self.to_sequence(env)
else:
return self.to_tensor(env)
return self.value
示例6: to_tensor
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def to_tensor(self, env: 'utils.Env',
dtype: type = None) -> onnx.ValueInfoProto:
if self.is_py:
self.const_value = Value(self.value)
# TODO(hamaji): Rewrite `totensor` to convert a Python
# list to a tensor.
self.value = utils.totensor(self.value, env, dtype=dtype)
self.is_py = False
else:
if self.is_sequence():
self.value = env.calc('ConcatFromSequence',
inputs=[self.value.name],
axis=0,
new_axis=True)
self.is_py = False
if dtype is not None:
dt = utils.onnx_dtype(dtype)
self.value = env.calc(
'Cast',
inputs=[self.value.name],
to=dt
)
self.value.type.tensor_type.elem_type = dt
assert self.is_tensor()
return self.value
示例7: to_sequence
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def to_sequence(self, env: 'utils.Env') -> onnx.ValueInfoProto:
if self.is_py:
self.const_value = Value(self.value)
if not isinstance(self.value, collections.Iterable):
raise TypeError('Expected a sequence: %s' % self.value)
res = env.calc_seq(
"SequenceConstruct",
inputs=[],
)
for v in self.value:
v = Value(v).to_tensor(env)
res = env.calc_seq(
"SequenceInsert",
inputs=[res.name, v.name],
)
self.value = res
self.is_py = False
elif self.is_tensor():
self.value = env.calc_seq(
'SplitToSequence',
inputs=[self.value.name],
keepdims=False
)
assert self.is_sequence()
return self.value
示例8: istensor
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def istensor(x):
return isinstance(x, onnx.ValueInfoProto)
示例9: eval_ast
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def eval_ast(nast, env):
for k, v in env.get_var_dict().items():
assert not isinstance(v, onnx.ValueInfoProto), '%s %s' % (k, v)
global _eval_ast_depth
if not isinstance(nast, list):
dprint('-' * _eval_ast_depth, gast.dump(nast), env.get_var_dict().keys())
_eval_ast_depth += 1
r = eval_ast_impl(nast, env)
_eval_ast_depth -= 1
return _value(r)
示例10: _input_from_onnx_input
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _input_from_onnx_input(input): # type: (ValueInfoProto) -> EdgeInfo
name = input.name
type = input.type.tensor_type.elem_type
shape = tuple([d.dim_value for d in input.type.tensor_type.shape.dim])
return (name, type, shape)
示例11: _shape_from_onnx_value_info
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _shape_from_onnx_value_info(v): # type: (ValueInfoProto) -> Sequence[Tuple[int, ...]]
return tuple([d.dim_value for d in v.type.tensor_type.shape.dim])
示例12: _add_utility_constants
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _add_utility_constants(self):
util_consts = {CONST_ONE_FP32: np.array([1.0]).astype(np.float32)}
# Add a few useful utility constants:
for name, value in util_consts.items():
self.add_const_explicit(name=name, value=value)
self.add_const_proto_explicit(
name=name, value=value, np_dtype=value.dtype)
self.add_input_proto_explicit(
name=name, shape=value.shape, np_dtype=value.dtype)
# This list holds the protobuf objects of type ValueInfoProto
# representing the input to the converted ONNX graph.
示例13: data_type_cast_map
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def data_type_cast_map(self, data_type_cast_map):
self._data_type_cast_map = data_type_cast_map
# This list holds the protobuf objects of type ValueInfoProto
# representing the all nodes' outputs to the converted ONNX graph.
示例14: _data_type_caster
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _data_type_caster(cls, protos, data_type_cast_map):
"""Cast to a new data type if node name is in data_type_cast_map.
Be used to process protos to match ONNX type constraints.
:param protos: Target protos.
TensorProto for inputs and ValueInfoProto for consts.
:param data_type_cast_map: A {node.name: new_data_type} dict.
:return: Processed protos.
"""
if not data_type_cast_map:
return protos
result = []
for proto in protos:
new_proto = proto
if proto.name in data_type_cast_map:
new_data_type = data_type_cast_map[proto.name]
if type(proto) == TensorProto and proto.data_type != new_data_type:
field = mapping.STORAGE_TENSOR_TYPE_TO_FIELD[
mapping.TENSOR_TYPE_TO_STORAGE_TENSOR_TYPE[proto.data_type]]
vals = getattr(proto, field)
new_proto = make_tensor(
name=proto.name,
data_type=new_data_type,
dims=proto.dims,
vals=vals)
elif type(
proto
) == ValueInfoProto and proto.type.tensor_type.elem_type != new_data_type:
new_proto.type.tensor_type.elem_type = new_data_type
result.append(new_proto)
return result
示例15: _make_graph
# 需要导入模块: import onnx [as 别名]
# 或者: from onnx import ValueInfoProto [as 别名]
def _make_graph(self,
seed_values, # type: Sequence[Union[Text, Tuple[Text, TensorProto.DataType, Any]]]
nodes, # type: List[NodeProto]
value_info, # type: List[ValueInfoProto]
initializer=None # type: Optional[Sequence[TensorProto]]
): # type: (...) -> GraphProto
if initializer is None:
initializer = []
names_in_initializer = set(x.name for x in initializer)
input_value_infos = []
# If the starting values are not also initializers,
# introduce the starting values as the output of reshape,
# so that the sizes are guaranteed to be unknown
for seed_value in seed_values:
if isinstance(seed_value, tuple):
seed_name = seed_value[0]
seed_value_info = make_tensor_value_info(*seed_value)
else:
seed_name = seed_value
seed_value_info = make_empty_tensor_value_info(seed_value)
if seed_name in names_in_initializer:
input_value_infos.append(seed_value_info)
else:
value_info.append(seed_value_info)
input_value_infos.append(make_tensor_value_info('SEED_' + seed_name, TensorProto.UNDEFINED, ()))
input_value_infos.append(make_tensor_value_info('UNKNOWN_SHAPE_' + seed_name, TensorProto.UNDEFINED, ()))
nodes[:0] = [make_node("Reshape", ['SEED_' + seed_name, 'UNKNOWN_SHAPE_' + seed_name], [seed_name])]
return helper.make_graph(nodes, "test", input_value_infos, [], initializer=initializer, value_info=value_info)