aboutsummaryrefslogtreecommitdiffstats
path: root/model-integration/src/test/models/onnx/simple/const.py
blob: 35d6dee1346af5ede4378bb227973c0510c47210 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
import onnx
import numpy as np
from onnx import helper, TensorProto

output_type = helper.make_tensor_value_info('y', TensorProto.FLOAT, [])

node = onnx.helper.make_node(
    'Constant',
    inputs=[],
    outputs=['y'],
    value=onnx.helper.make_tensor(
        name='const_tensor',
        data_type=onnx.TensorProto.FLOAT,
        dims=(),
        vals=[0.42]
    ),
)
graph_def = onnx.helper.make_graph(
    nodes = [node],
    name = 'constant_test',
    inputs = [],
    outputs = [output_type]
)
model_def = helper.make_model(graph_def, producer_name='const.py')
onnx.save(model_def, 'const.onnx')