本文整理汇总了Python中onnx.TensorProto.FLOAT属性的典型用法代码示例。如果您正苦于以下问题:Python TensorProto.FLOAT属性的具体用法?Python TensorProto.FLOAT怎么用?Python TensorProto.FLOAT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类onnx.TensorProto
的用法示例。
在下文中一共展示了TensorProto.FLOAT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_broadcast
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_broadcast():
"""Test for broadcasting in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Add", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"bcast_test",
inputs,
outputs)
bcast_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(bcast_model)
numpy_op = input1 + input2
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例2: test_greater
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_greater():
"""Test for logical greater in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Greater", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"greater_test",
inputs,
outputs)
greater_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(greater_model)
numpy_op = np.greater(input1, input2).astype(np.float32)
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例3: test_lesser
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_lesser():
"""Test for logical greater in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Less", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"lesser_test",
inputs,
outputs)
greater_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(greater_model)
numpy_op = np.less(input1, input2).astype(np.float32)
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例4: test_equal
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_equal():
"""Test for logical greater in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Equal", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"equal_test",
inputs,
outputs)
greater_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(greater_model)
numpy_op = np.equal(input1, input2).astype(np.float32)
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例5: _create_param_tensors
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def _create_param_tensors(self, conv_params, param_category, suffix):
"""Creates the initializers with weights from the weights file together with
the input tensors.
Keyword arguments:
conv_params -- a ConvParams object
param_category -- the category of parameters to be created ('bn' or 'conv')
suffix -- a string determining the sub-type of above param_category (e.g.,
'weights' or 'bias')
"""
param_name, param_data, param_data_shape = self._load_one_param_type(
conv_params, param_category, suffix)
initializer_tensor = helper.make_tensor(
param_name, TensorProto.FLOAT, param_data_shape, param_data)
input_tensor = helper.make_tensor_value_info(
param_name, TensorProto.FLOAT, param_data_shape)
return initializer_tensor, input_tensor
示例6: _make_input_tensor
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def _make_input_tensor(self, layer_name, layer_dict):
"""Create an ONNX input tensor from a 'net' layer and store the batch size.
Keyword arguments:
layer_name -- the layer's name (also the corresponding key in layer_configs)
layer_dict -- a layer parameter dictionary (one element of layer_configs)
"""
batch_size = layer_dict['batch']
channels = layer_dict['channels']
height = layer_dict['height']
width = layer_dict['width']
self.batch_size = batch_size
input_tensor = helper.make_tensor_value_info(
str(layer_name), TensorProto.FLOAT, [
batch_size, channels, height, width])
self.input_tensor = input_tensor
return layer_name, channels
示例7: load_resize_scales
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def load_resize_scales(self, resize_params):
"""Returns the initializers with the value of the scale input
tensor given by resize_params.
Keyword argument:
resize_params -- a ResizeParams object
"""
initializer = list()
inputs = list()
name = resize_params.generate_param_name()
shape = resize_params.value.shape
data = resize_params.value
scale_init = helper.make_tensor(
name, TensorProto.FLOAT, shape, data)
scale_input = helper.make_tensor_value_info(
name, TensorProto.FLOAT, shape)
initializer.append(scale_init)
inputs.append(scale_input)
return initializer, inputs
示例8: __init__
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def __init__(self, ch):
super(Link_Linear, self).__init__(lambda x, n_batch_axes=1: x)
if ch.b is None:
self.n_out = 'output_size'
self.nobias = True
else:
self.n_out = ch.b.shape[0]
self.nobias = False
if not(ch.W.data is None):
self.n_in = ch.W.shape[1]
else:
self.n_in = None
self.W = helper.make_tensor_value_info(
'/W', TensorProto.FLOAT,
[self.n_out, ('input_size' if (self.n_in is None) else self.n_in)])
if not self.nobias:
self.b = helper.make_tensor_value_info(
'/b', TensorProto.FLOAT, [self.n_out])
示例9: generate_graph
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def generate_graph(self, name: 'str', isMain=False):
input_tensor_and_initializer = self.input_tensor.copy()
# TODO(take-cheeze): Remove this workaround
for i in input_tensor_and_initializer:
t = i.type.tensor_type
if t is not None and t.elem_type is TensorProto.UNDEFINED:
t.elem_type = TensorProto.FLOAT
initializers = []
# add initializers
if isMain:
for v in self.generator.initializers.values():
initializers.append(v.tensor)
if v.tensor_value in self.input_tensor:
continue
input_tensor_and_initializer.append(v.tensor_value)
return oh.make_graph(self.nodes, name, input_tensor_and_initializer, self.output_tensor, initializer=initializers)
示例10: __call__
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def __call__(self, graph): # type: (Graph) -> Graph
input_names = [str(input_[0]) for input_ in graph.inputs]
output_names = [str(output_[0]) for output_ in graph.outputs]
for node in graph.nodes:
if str(node.op_type) == 'LSTM':
input_h = node.inputs[5] if len(node.inputs) > 5 else node.inputs[0] + '_h_input'
input_c = node.inputs[6] if len(node.inputs) > 6 else node.inputs[0] + '_c_input'
output_h = node.outputs[1] if len(node.outputs) > 1 else node.outputs[0] + '_h_output'
output_c = node.outputs[2] if len(node.outputs) > 2 else node.outputs[0] + '_c_output'
h = node.attrs["hidden_size"]
for input_ in [str(input_h), str(input_c)]:
if input_ not in input_names:
graph.inputs.append(tuple((input_, TensorProto.FLOAT, (h,)))) #type: ignore
if input_ not in graph.blob_to_op_type:
graph.blob_to_op_type[input_] = ['LSTM']
for output_ in [str(output_h), str(output_c)]:
if output_ not in output_names:
graph.outputs.append(tuple((output_, TensorProto.FLOAT, (h,)))) #type: ignore
graph.blob_from_op_type[output_] = 'LSTM'
return graph
示例11: _onnx_create_single_node_model
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def _onnx_create_single_node_model(op_type, # type: Text
input_shapes, # type: Sequence[Tuple[int, ...]]
output_shapes, # type: Sequence[Tuple[int, ...]]
initializer=[], # type: Sequence[TensorProto]
**kwargs # type: Any
):
# type: (...) -> ModelProto
inputs = [
("input{}".format(i,), input_shapes[i])
for i in range(len(input_shapes))
]
outputs = [
("output{}".format(i,), output_shapes[i], TensorProto.FLOAT)
for i in range(len(output_shapes))
]
node = helper.make_node(
op_type,
inputs=[i[0] for i in inputs] + [t.name for t in initializer],
outputs=[o[0] for o in outputs],
**kwargs
)
return _onnx_create_model([node], inputs, outputs, initializer)
示例12: _make_model_acos_exp_topk
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def _make_model_acos_exp_topk(): # type: (...) -> ModelProto
'''
make a very simple model for testing: input->clip->exp->topk->2 outputs
'''
inputs = [('input0', (10,), TensorProto.FLOAT), ('K', (1,), TensorProto.INT64)]
outputs = [('output_values', (3,), TensorProto.FLOAT), ('output_indices', (3,), TensorProto.INT64)]
acos = helper.make_node("Acos",
inputs=[inputs[0][0]],
outputs=['acos_out'])
exp = helper.make_node("Exp",
inputs=[acos.output[0]],
outputs=['exp_out'])
topk = helper.make_node("TopK",
inputs=[exp.output[0], inputs[1][0]],
outputs=[outputs[0][0], outputs[1][0]],
axis=0)
return _onnx_create_model([acos, exp, topk], inputs, outputs)
示例13: test_relu_node_inplace
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_relu_node_inplace(self):
X = np.random.randn(3, 2).astype(np.float32)
Y_ref = np.clip(X, 0, np.inf)
node_def = helper.make_node("Relu", ["X"], ["X1"])
graph_def = helper.make_graph(
[node_def],
name="test",
inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, [3, 2])],
outputs=[
helper.make_tensor_value_info("X1", TensorProto.FLOAT, [3, 2])
])
tf_rep = prepare(helper.make_model(graph_def))
output = tf_rep.run({"X": X})
np.testing.assert_almost_equal(output.X1, Y_ref)
示例14: test_eye_like
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_eye_like(self):
if legacy_opset_pre_ver(9):
raise unittest.SkipTest("ONNX version {} doesn't support EyeLike.".format(
defs.onnx_opset_version()))
shape = [6, 10]
off_diagonal_offset = -3
x = self._get_rnd_int(0, 100, shape=shape)
y = np.eye(shape[0], shape[1], k=off_diagonal_offset, dtype=np.float32)
node_def = helper.make_node("EyeLike", ["x"], ["y"],
dtype=TensorProto.FLOAT,
k=off_diagonal_offset)
graph_def = helper.make_graph(
[node_def],
name="test_unknown_shape",
inputs=[
helper.make_tensor_value_info("x", TensorProto.INT32, [None, None])
],
outputs=[
helper.make_tensor_value_info("y", TensorProto.FLOAT, [None, None])
])
tf_rep = onnx_graph_to_tensorflow_rep(graph_def)
output = tf_rep.run({"x": x})
np.testing.assert_equal(output["y"], y)
示例15: test_flatten
# 需要导入模块: from onnx import TensorProto [as 别名]
# 或者: from onnx.TensorProto import FLOAT [as 别名]
def test_flatten(self):
shape = [2, 3, 4]
x = self._get_rnd_float32(shape=shape)
axis = 1
node_def = helper.make_node("Flatten", ["X"], ["Y"], axis=axis)
graph_def = helper.make_graph(
[node_def],
name="test_unknown_shape",
inputs=[
helper.make_tensor_value_info("X", TensorProto.FLOAT,
[None, None, None])
],
outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, [None])])
tf_rep = onnx_graph_to_tensorflow_rep(graph_def)
output = tf_rep.run({"X": x})
new_shape = (np.prod(shape[0:axis]).astype(int), -1)
np.testing.assert_almost_equal(output["Y"], np.reshape(x, new_shape))