當前位置: 首頁>>代碼示例>>Python>>正文


Python helper.make_tensor_value_info方法代碼示例

本文整理匯總了Python中onnx.helper.make_tensor_value_info方法的典型用法代碼示例。如果您正苦於以下問題:Python helper.make_tensor_value_info方法的具體用法?Python helper.make_tensor_value_info怎麽用?Python helper.make_tensor_value_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在onnx.helper的用法示例。


在下文中一共展示了helper.make_tensor_value_info方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_broadcast

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:24,代碼來源:onnx_import_test.py

示例2: test_greater

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:24,代碼來源:onnx_import_test.py

示例3: test_lesser

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:24,代碼來源:onnx_import_test.py

示例4: test_equal

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:24,代碼來源:onnx_import_test.py

示例5: _create_param_tensors

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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 
開發者ID:aimuch,項目名稱:iAI,代碼行數:20,代碼來源:yolov3_to_onnx.py

示例6: _make_input_tensor

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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 
開發者ID:aimuch,項目名稱:iAI,代碼行數:19,代碼來源:yolov3_to_onnx.py

示例7: load_resize_scales

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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 
開發者ID:aimuch,項目名稱:iAI,代碼行數:21,代碼來源:yolov3_to_onnx.py

示例8: test_simple_graph

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [as 別名]
def test_simple_graph():
    node1 = make_node('Add', ['A', 'B'], ['X'], name='add_node1')
    node2 = make_node('Add', ['X', 'C'], ['Y'], name='add_node2')
    graph = make_graph([node1, node2], 'test_graph',
                       [make_tensor_value_info('A', onnx.TensorProto.FLOAT, [1]),
                        make_tensor_value_info('B', onnx.TensorProto.FLOAT, [1]),
                        make_tensor_value_info('C', onnx.TensorProto.FLOAT, [1])],
                       [make_tensor_value_info('Y', onnx.TensorProto.FLOAT, [1])])
    model = make_model(graph, producer_name='ngraph ONNXImporter')

    ng_model_function = import_onnx_model(model)

    runtime = get_runtime()
    computation = runtime.computation(ng_model_function)
    assert np.array_equal(computation(1, 2, 3)[0], np.array([6.0], dtype=np.float32))
    assert np.array_equal(computation(4, 5, 6)[0], np.array([15.0], dtype=np.float32)) 
開發者ID:NervanaSystems,項目名稱:ngraph-onnx,代碼行數:18,代碼來源:test_graph_import.py

示例9: test_identity

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [as 別名]
def test_identity():
    np.random.seed(133391)
    shape = [2, 4]
    input_data = np.random.randn(*shape).astype(np.float32)

    identity_node = make_node('Identity', inputs=['x'], outputs=['y'])
    ng_results = run_node(identity_node, [input_data])
    assert np.array_equal(ng_results, [input_data])

    node1 = make_node('Add', inputs=['A', 'B'], outputs=['add1'], name='add_node1')
    node2 = make_node('Identity', inputs=['add1'], outputs=['identity1'], name='identity_node1')
    node3 = make_node('Abs', inputs=['identity1'], outputs=['Y'], name='abs_node1')

    graph = make_graph([node1, node2, node3], 'test_graph',
                       [make_tensor_value_info('A', onnx.TensorProto.FLOAT, shape),
                        make_tensor_value_info('B', onnx.TensorProto.FLOAT, shape)],
                       [make_tensor_value_info('Y', onnx.TensorProto.FLOAT, shape)])
    model = make_model(graph, producer_name='ngraph ONNX Importer')
    ng_model_function = import_onnx_model(model)
    runtime = get_runtime()
    computation = runtime.computation(ng_model_function)
    ng_results = computation(input_data, input_data)
    expected_result = np.abs(input_data + input_data)

    assert np.array_equal(ng_results[0], expected_result) 
開發者ID:NervanaSystems,項目名稱:ngraph-onnx,代碼行數:27,代碼來源:test_ops_unary.py

示例10: make_onnx_model_for_gemm_op

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [as 別名]
def make_onnx_model_for_gemm_op(input_a, input_b, input_c, **kwargs):
    input_a_for_output = input_a
    input_b_for_output = input_b
    if kwargs.get('transA'):
        input_a_for_output = input_a.T
    if kwargs.get('transB'):
        input_b_for_output = input_b.T

    output_shape = np.dot(input_a_for_output, input_b_for_output).shape
    node = make_node('Gemm', ['A', 'B', 'C'], ['Y'], name='test_node', **kwargs)
    graph = make_graph([node], 'test_graph',
                       [make_tensor_value_info('A', onnx.TensorProto.FLOAT, input_a.shape),
                        make_tensor_value_info('B', onnx.TensorProto.FLOAT, input_b.shape),
                        make_tensor_value_info('C', onnx.TensorProto.FLOAT, input_c.shape)],
                       [make_tensor_value_info('Y', onnx.TensorProto.FLOAT, output_shape)])
    model = make_model(graph, producer_name='ngraph ONNXImporter')
    return model 
開發者ID:NervanaSystems,項目名稱:ngraph-onnx,代碼行數:19,代碼來源:test_ops_matmul.py

示例11: __init__

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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]) 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:24,代碼來源:links.py

示例12: new_tensor_impl

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [as 別名]
def new_tensor_impl(self, ndarray_, name):
        '''
        generate a tensor which contains np data
        it is for constant input
        '''

        if not config.float_restrict:
            if ndarray_.dtype == np.float64:
                ndarray_ = ndarray_.astype(np.float32)

        tensor = numpy_helper.from_array(ndarray_, name=name)
        dt = onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(ndarray_.dtype)]

        tensor_value = oh.make_tensor_value_info(name, dt, ndarray_.shape)

        self.generator.onnx_tensors[name] = tensor_value

        return tensor, tensor_value 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:20,代碼來源:onnx_converters.py

示例13: test_eye_like

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [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) 
開發者ID:onnx,項目名稱:onnx-tensorflow,代碼行數:25,代碼來源:test_dynamic_shape.py

示例14: test_gather_nd

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [as 別名]
def test_gather_nd(self):
    if legacy_opset_pre_ver(11):
      raise unittest.SkipTest(
          "ONNX version {} doesn't support GatherND.".format(
              defs.onnx_opset_version()))
    # valid positive and negative indices for elements
    data = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int32)
    indices = np.array([[0, 0], [1, -3]], dtype=np.int64)
    ref_output = np.array([1, 4], dtype=np.int32)
    node_def = helper.make_node("GatherND", ["data", "indices"], ["outputs"])
    graph_def = helper.make_graph(
        [node_def],
        name="test_unknown_shape",
        inputs=[
            helper.make_tensor_value_info("data", TensorProto.INT32,
                                          [None, None]),
            helper.make_tensor_value_info("indices", TensorProto.INT64,
                                          [None, None])
        ],
        outputs=[
            helper.make_tensor_value_info("outputs", TensorProto.INT32, [None])
        ])
    tf_rep = onnx_graph_to_tensorflow_rep(graph_def)
    output = tf_rep.run({"data": data, "indices": indices})
    np.testing.assert_almost_equal(output["outputs"], ref_output) 
開發者ID:onnx,項目名稱:onnx-tensorflow,代碼行數:27,代碼來源:test_dynamic_shape.py

示例15: test_is_inf

# 需要導入模塊: from onnx import helper [as 別名]
# 或者: from onnx.helper import make_tensor_value_info [as 別名]
def test_is_inf(self):
    if legacy_opset_pre_ver(10):
      raise unittest.SkipTest("ONNX version {} doesn't support IsInf.".format(
          defs.onnx_opset_version()))
    inp = np.array([-1.2, np.nan, np.inf, 2.8, np.NINF, np.inf],
                   dtype=np.float32)
    expected_output = np.isinf(inp)
    node_def = helper.make_node("IsInf", ["X"], ["Y"])
    graph_def = helper.make_graph(
        [node_def],
        name="test_unknown_shape",
        inputs=[
            helper.make_tensor_value_info("X", TensorProto.FLOAT, [None]),
        ],
        outputs=[helper.make_tensor_value_info("Y", TensorProto.BOOL, [None])])
    tf_rep = onnx_graph_to_tensorflow_rep(graph_def)
    output = tf_rep.run({"X": inp})
    np.testing.assert_equal(output["Y"], expected_output) 
開發者ID:onnx,項目名稱:onnx-tensorflow,代碼行數:20,代碼來源:test_dynamic_shape.py


注:本文中的onnx.helper.make_tensor_value_info方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。