Commit 4295961c authored by Khalique's avatar Khalique
Browse files

formatting

parent 53349569
...@@ -4,28 +4,26 @@ from onnx import helper ...@@ -4,28 +4,26 @@ from onnx import helper
from onnx import numpy_helper from onnx import numpy_helper
from onnx import AttributeProto, TensorProto, GraphProto from onnx import AttributeProto, TensorProto, GraphProto
def onnx_test(op_test): def onnx_test(op_test):
def run_test(): def run_test():
op_info = op_test() op_info = op_test()
if len(op_info) > 3: if len(op_info) > 3:
graph_def = helper.make_graph( graph_def = helper.make_graph(op_info[0],
op_info[0], op_test.__name__,
op_test.__name__, op_info[1],
op_info[1], op_info[2],
op_info[2], initializer=op_info[3])
initializer=op_info[3]
)
else: else:
graph_def = helper.make_graph( graph_def = helper.make_graph(op_info[0], op_test.__name__,
op_info[0], op_info[1], op_info[2])
op_test.__name__, model_def = helper.make_model(graph_def,
op_info[1], producer_name=op_test.__name__)
op_info[2]
)
model_def = helper.make_model(graph_def, producer_name=op_test.__name__)
onnx.save(model_def, '{}.onnx'.format(op_test.__name__)) onnx.save(model_def, '{}.onnx'.format(op_test.__name__))
return run_test return run_test
@onnx_test @onnx_test
def acos_test(): def acos_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
...@@ -39,21 +37,21 @@ def acos_test(): ...@@ -39,21 +37,21 @@ def acos_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def add_bcast_test(): def add_bcast_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 4]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 4])
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [2, 3, 4,5]) z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node('Add',
'Add', inputs=['0', '1'],
inputs=['0', '1'], broadcast=1,
broadcast=1, axis=1,
axis=1, outputs=['2'])
outputs=['2']
) return ([node], [x, y], [z])
return ([node], [x,y], [z])
@onnx_test @onnx_test
def add_fp16_test(): def add_fp16_test():
...@@ -69,65 +67,55 @@ def add_fp16_test(): ...@@ -69,65 +67,55 @@ def add_fp16_test():
return ( return (
[node], [node],
[x,y], [x, y],
[z], [z],
# '0' -> 1.5, '1' -> 2.5 # '0' -> 1.5, '1' -> 2.5
[onnx.helper.make_tensor('0', TensorProto.FLOAT16, [1], [15872]), [
onnx.helper.make_tensor('1', TensorProto.FLOAT16, [1], [16640])] onnx.helper.make_tensor('0', TensorProto.FLOAT16, [1], [15872]),
) onnx.helper.make_tensor('1', TensorProto.FLOAT16, [1], [16640])
])
model_def = helper.make_model(graph_def, producer_name=('add-fp16-example'))
onnx.save(model_def, 'add_fp16_test.onnx')
@onnx_test @onnx_test
def add_scalar_test(): def add_scalar_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, []) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [])
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [2, 3, 4,5]) z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node('Add', inputs=['0', '1'], outputs=['2'])
'Add',
inputs=['0', '1'], return ([node], [x, y], [z],
outputs=['2'] [helper.make_tensor('1', TensorProto.FLOAT, [], [1])])
)
return (
[node],
[x,y],
[z],
[helper.make_tensor('1', TensorProto.FLOAT, [], [1])]
)
@onnx_test @onnx_test
def argmax_test(): def argmax_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 6]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 6])
node = onnx.helper.make_node( node = onnx.helper.make_node('ArgMax',
'ArgMax', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axis=2,
axis=2, keepdims=0)
keepdims = 0
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def argmin_test(): def argmin_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 5]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node('ArgMin',
'ArgMin', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axis=3,
axis=3, keepdims=0)
keepdims = 0
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def asin_test(): def asin_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
...@@ -152,39 +140,34 @@ def atan_test(): ...@@ -152,39 +140,34 @@ def atan_test():
inputs=['x'], inputs=['x'],
outputs=['y'], outputs=['y'],
) )
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def cast_test(): def cast_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT16, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT16, [10])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [10]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [10])
node = onnx.helper.make_node( node = onnx.helper.make_node('Cast', inputs=['x'], outputs=['y'], to=1)
'Cast',
inputs=['x'],
outputs=['y'],
to = 1
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def clip_test(): def clip_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3])
node = onnx.helper.make_node('Clip',
node = onnx.helper.make_node( inputs=['0'],
'Clip', outputs=['1'],
inputs=['0'], max=6.0,
outputs=['1'], min=0.0)
max=6.0,
min=0.0
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def concat_test(): def concat_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 4, 3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 4, 3])
...@@ -198,13 +181,14 @@ def concat_test(): ...@@ -198,13 +181,14 @@ def concat_test():
outputs=['2'], outputs=['2'],
) )
return ([node], [x,y], [z]) return ([node], [x, y], [z])
@onnx_test @onnx_test
def constant_test(): def constant_test():
x = np.array([0, 1, 2]) x = np.array([0, 1, 2])
y = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3]) y = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Constant', 'Constant',
inputs=[], inputs=[],
...@@ -219,6 +203,7 @@ def constant_test(): ...@@ -219,6 +203,7 @@ def constant_test():
return ([node], [], [y]) return ([node], [], [y])
@onnx_test @onnx_test
def constant_fill_test(): def constant_fill_test():
value = helper.make_tensor_value_info('value', TensorProto.FLOAT, [2, 3]) value = helper.make_tensor_value_info('value', TensorProto.FLOAT, [2, 3])
...@@ -227,26 +212,25 @@ def constant_fill_test(): ...@@ -227,26 +212,25 @@ def constant_fill_test():
'ConstantFill', 'ConstantFill',
inputs=[], inputs=[],
outputs=['value'], outputs=['value'],
dtype = 1, dtype=1,
value = 1.0, value=1.0,
shape = [2, 3], shape=[2, 3],
input_as_shape = 0, input_as_shape=0,
) )
return ([node], [], [value]) return ([node], [], [value])
@onnx_test @onnx_test
def constant_fill_input_as_shape_test(): def constant_fill_input_as_shape_test():
np_shape = np.array([2, 3]) np_shape = np.array([2, 3])
shape = helper.make_tensor_value_info('shape', TensorProto.INT32, [2]) shape = helper.make_tensor_value_info('shape', TensorProto.INT32, [2])
value = helper.make_tensor_value_info('value', TensorProto.FLOAT, [2, 3]) value = helper.make_tensor_value_info('value', TensorProto.FLOAT, [2, 3])
ts_shape = helper.make_tensor( ts_shape = helper.make_tensor(name='shape_tensor',
name = 'shape_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=np_shape.shape,
dims = np_shape.shape, vals=np_shape.flatten().astype(int))
vals = np_shape.flatten().astype(int)
)
const_shape_node = onnx.helper.make_node( const_shape_node = onnx.helper.make_node(
'Constant', 'Constant',
...@@ -259,13 +243,14 @@ def constant_fill_input_as_shape_test(): ...@@ -259,13 +243,14 @@ def constant_fill_input_as_shape_test():
'ConstantFill', 'ConstantFill',
inputs=['shape'], inputs=['shape'],
outputs=['value'], outputs=['value'],
dtype = 1, dtype=1,
value = 1.0, value=1.0,
input_as_shape = 1, input_as_shape=1,
) )
return ([const_shape_node, node], [], [value]) return ([const_shape_node, node], [], [value])
@onnx_test @onnx_test
def constant_scalar_test(): def constant_scalar_test():
x = np.array([1]) x = np.array([1])
...@@ -285,20 +270,17 @@ def constant_scalar_test(): ...@@ -285,20 +270,17 @@ def constant_scalar_test():
return ([node], [], [y]) return ([node], [], [y])
@onnx_test @onnx_test
def const_of_shape_empty_input_test(): def const_of_shape_empty_input_test():
tensor_val = onnx.helper.make_tensor( tensor_val = onnx.helper.make_tensor('value', onnx.TensorProto.INT64, [1],
'value', [10])
onnx.TensorProto.INT64, [1],[10]
)
shape_val = np.array([2, 3, 4]).astype(np.int64) shape_val = np.array([2, 3, 4]).astype(np.int64)
empty_val = np.array([]).astype(np.int64) empty_val = np.array([]).astype(np.int64)
empty_ts = helper.make_tensor( empty_ts = helper.make_tensor(name='empty_tensor',
name='empty_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=empty_val.shape,
dims=empty_val.shape, vals=empty_val.flatten().astype(int))
vals=empty_val.flatten().astype(int)
)
shape_const = helper.make_node( shape_const = helper.make_node(
'Constant', 'Constant',
inputs=[], inputs=[],
...@@ -311,24 +293,22 @@ def const_of_shape_empty_input_test(): ...@@ -311,24 +293,22 @@ def const_of_shape_empty_input_test():
'ConstantOfShape', 'ConstantOfShape',
inputs=['shape'], inputs=['shape'],
outputs=['y'], outputs=['y'],
value = tensor_val, value=tensor_val,
) )
return ([shape_const, node], [], [y]) return ([shape_const, node], [], [y])
@onnx_test @onnx_test
def const_of_shape_float_test(): def const_of_shape_float_test():
tensor_val = onnx.helper.make_tensor( tensor_val = onnx.helper.make_tensor('value', onnx.TensorProto.FLOAT, [1],
'value', [10])
onnx.TensorProto.FLOAT, [1],[10])
shape_val = np.array([2, 3, 4]).astype(np.int64) shape_val = np.array([2, 3, 4]).astype(np.int64)
shape_ts = helper.make_tensor( shape_ts = helper.make_tensor(name='shape_tensor',
name = 'shape_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=shape_val.shape,
dims = shape_val.shape, vals=shape_val.flatten().astype(int))
vals = shape_val.flatten().astype(int)
)
shape_const = helper.make_node( shape_const = helper.make_node(
'Constant', 'Constant',
...@@ -338,54 +318,46 @@ def const_of_shape_float_test(): ...@@ -338,54 +318,46 @@ def const_of_shape_float_test():
) )
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4])
node = onnx.helper.make_node( node = onnx.helper.make_node('ConstantOfShape',
'ConstantOfShape', inputs=['shape'],
inputs=['shape'], outputs=['y'],
outputs=['y'], value=tensor_val)
value = tensor_val
)
return ([shape_const, node], [], [y]) return ([shape_const, node], [], [y])
@onnx_test @onnx_test
def const_of_shape_int64_test(): def const_of_shape_int64_test():
tensor_val = onnx.helper.make_tensor( tensor_val = onnx.helper.make_tensor('value', onnx.TensorProto.INT64, [1],
'value', [10])
onnx.TensorProto.INT64, [1],[10]
)
shape_val = np.array([2, 3, 4]).astype(np.int64) shape_val = np.array([2, 3, 4]).astype(np.int64)
shape_ts = helper.make_tensor( shape_ts = helper.make_tensor(name='shape_tensor',
name = 'shape_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=shape_val.shape,
dims = shape_val.shape, vals=shape_val.flatten().astype(int))
vals = shape_val.flatten().astype(int)
)
shape_const = helper.make_node( shape_const = helper.make_node(
'Constant', 'Constant',
inputs=[], inputs=[],
outputs=['shape'], outputs=['shape'],
value=shape_ts, value=shape_ts,
) )
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4])
node = onnx.helper.make_node( node = onnx.helper.make_node('ConstantOfShape',
'ConstantOfShape', inputs=['shape'],
inputs=['shape'], outputs=['y'],
outputs=['y'], value=tensor_val)
value = tensor_val
)
return ([shape_const, node], [], [y]) return ([shape_const, node], [], [y])
@onnx_test @onnx_test
def const_of_shape_no_value_attr_test(): def const_of_shape_no_value_attr_test():
shape_val = np.array([2, 3, 4]).astype(np.int64) shape_val = np.array([2, 3, 4]).astype(np.int64)
shape_ts = helper.make_tensor( shape_ts = helper.make_tensor(name='shape_tensor',
name = 'shape_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=shape_val.shape,
dims = shape_val.shape, vals=shape_val.flatten().astype(int))
vals = shape_val.flatten().astype(int)
)
shape_const = helper.make_node( shape_const = helper.make_node(
'Constant', 'Constant',
inputs=[], inputs=[],
...@@ -393,7 +365,7 @@ def const_of_shape_no_value_attr_test(): ...@@ -393,7 +365,7 @@ def const_of_shape_no_value_attr_test():
value=shape_ts, value=shape_ts,
) )
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'ConstantOfShape', 'ConstantOfShape',
inputs=['shape'], inputs=['shape'],
...@@ -402,23 +374,23 @@ def const_of_shape_no_value_attr_test(): ...@@ -402,23 +374,23 @@ def const_of_shape_no_value_attr_test():
return ([shape_const, node], [], [y]) return ([shape_const, node], [], [y])
@onnx_test @onnx_test
def conv_autopad_fail_test(): def conv_autopad_fail_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 32, 32]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 32, 32])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 1, 1]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 1, 1])
out = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1, 1, 34, 34]) out = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1, 1, 34, 34])
node = onnx.helper.make_node( node = onnx.helper.make_node('Conv',
'Conv', inputs=['0', '1'],
inputs=['0', '1'], outputs=['2'],
outputs=['2'], dilations=[1, 1],
dilations = [1, 1], strides=[1, 1],
strides = [1, 1], auto_pad='SAME',
auto_pad = 'SAME', pads=[0, 0, 1, 1, 0, 0, 1, 1])
pads = [0,0,1,1,0,0,1,1]
) return ([node], [x, y], [out])
return ([node], [x,y], [out])
@onnx_test @onnx_test
def conv_bias_test(): def conv_bias_test():
...@@ -427,15 +399,14 @@ def conv_bias_test(): ...@@ -427,15 +399,14 @@ def conv_bias_test():
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1]) z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1])
out = helper.make_tensor_value_info('3', TensorProto.FLOAT, [1, 2, 28, 28]) out = helper.make_tensor_value_info('3', TensorProto.FLOAT, [1, 2, 28, 28])
node = onnx.helper.make_node( node = onnx.helper.make_node('Conv',
'Conv', inputs=['0', '1', '2'],
inputs=['0', '1', '2'], outputs=['3'],
outputs=['3'], dilations=[1, 1],
dilations = [1, 1], strides=[1, 1])
strides = [1, 1]
) return ([node], [x, y, z], [out])
return ([node], [x,y,z], [out])
@onnx_test @onnx_test
def conv_bn_relu_maxpool_test(): def conv_bn_relu_maxpool_test():
...@@ -446,44 +417,32 @@ def conv_bn_relu_maxpool_test(): ...@@ -446,44 +417,32 @@ def conv_bn_relu_maxpool_test():
n = helper.make_tensor_value_info('4', TensorProto.FLOAT, [1]) n = helper.make_tensor_value_info('4', TensorProto.FLOAT, [1])
k = helper.make_tensor_value_info('5', TensorProto.FLOAT, [1]) k = helper.make_tensor_value_info('5', TensorProto.FLOAT, [1])
l = helper.make_tensor_value_info('6', TensorProto.FLOAT, [1]) l = helper.make_tensor_value_info('6', TensorProto.FLOAT, [1])
out = helper.make_tensor_value_info('10', TensorProto.FLOAT, [1, 1, 14, 14]) out = helper.make_tensor_value_info('10', TensorProto.FLOAT,
[1, 1, 14, 14])
node0 = onnx.helper.make_node( node0 = onnx.helper.make_node('Conv',
'Conv', inputs=['0', '1', '2'],
inputs=['0', '1', '2'], outputs=['7'],
outputs=['7'], dilations=[1, 1],
dilations = [1, 1], strides=[1, 1],
strides = [1, 1], pads=[0, 0, 0, 0])
pads = [0, 0, 0, 0]
)
node1 = onnx.helper.make_node( node1 = onnx.helper.make_node('BatchNormalization',
'BatchNormalization', inputs=['7', '3', '4', '5', '6'],
inputs=['7', '3', '4', '5', '6'], outputs=['8'],
outputs=['8'], epsilon=9.99999974737875e-06,
epsilon = 9.99999974737875e-06, momentum=0.899999976158142)
momentum = 0.899999976158142
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Relu', inputs=['8'], outputs=['9'])
'Relu', node3 = onnx.helper.make_node('MaxPool',
inputs=['8'], inputs=['9'],
outputs=['9'] outputs=['10'],
) pads=[0, 0, 0, 0],
node3 = onnx.helper.make_node( strides=[2, 2],
'MaxPool', kernel_shape=[2, 2])
inputs=['9'],
outputs=['10'], return ([node0, node1, node2, node3], [x, y, z, m, n, k, l], [out])
pads = [0, 0, 0, 0],
strides = [2, 2],
kernel_shape=[2,2]
)
return (
[node0, node1, node2, node3],
[x, y, z, m, n, k, l],
[out]
)
@onnx_test @onnx_test
def conv_relu_maxpool_test(): def conv_relu_maxpool_test():
...@@ -492,35 +451,24 @@ def conv_relu_maxpool_test(): ...@@ -492,35 +451,24 @@ def conv_relu_maxpool_test():
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1]) z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1])
out = helper.make_tensor_value_info('5', TensorProto.FLOAT, [1, 1, 14, 14]) out = helper.make_tensor_value_info('5', TensorProto.FLOAT, [1, 1, 14, 14])
node1 = onnx.helper.make_node( node1 = onnx.helper.make_node('Conv',
'Conv', inputs=['0', '1', '2'],
inputs=['0', '1', '2'], outputs=['3'],
outputs=['3'], dilations=[1, 1],
dilations = [1, 1], strides=[1, 1],
strides = [1, 1], pads=[0, 0, 0, 0])
pads = [0, 0, 0, 0]
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Relu', inputs=['3'], outputs=['4'])
'Relu',
inputs=['3'],
outputs=['4']
)
node3 = onnx.helper.make_node( node3 = onnx.helper.make_node('MaxPool',
'MaxPool', inputs=['4'],
inputs=['4'], outputs=['5'],
outputs=['5'], pads=[0, 0, 0, 0],
pads = [0, 0, 0, 0], strides=[2, 2],
strides = [2, 2], kernel_shape=[2, 2])
kernel_shape=[2,2]
) return ([node1, node2, node3], [x, y, z], [out])
return (
[node1, node2, node3],
[x, y, z],
[out]
)
@onnx_test @onnx_test
def conv_relu_maxpool_x2_test(): def conv_relu_maxpool_x2_test():
...@@ -531,59 +479,40 @@ def conv_relu_maxpool_x2_test(): ...@@ -531,59 +479,40 @@ def conv_relu_maxpool_x2_test():
n = helper.make_tensor_value_info('4', TensorProto.FLOAT, [1]) n = helper.make_tensor_value_info('4', TensorProto.FLOAT, [1])
out = helper.make_tensor_value_info('10', TensorProto.FLOAT, [1, 1, 5, 5]) out = helper.make_tensor_value_info('10', TensorProto.FLOAT, [1, 1, 5, 5])
node1 = onnx.helper.make_node( node1 = onnx.helper.make_node('Conv',
'Conv', inputs=['0', '1', '2'],
inputs=['0', '1', '2'], outputs=['5'],
outputs=['5'], dilations=[1, 1],
dilations = [1, 1], strides=[1, 1],
strides = [1, 1], pads=[0, 0, 0, 0])
pads = [0, 0, 0, 0]
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Relu', inputs=['5'], outputs=['6'])
'Relu',
inputs=['5'],
outputs=['6']
)
node3 = onnx.helper.make_node( node3 = onnx.helper.make_node('MaxPool',
'MaxPool', inputs=['6'],
inputs=['6'], outputs=['7'],
outputs=['7'], pads=[0, 0, 0, 0],
pads = [0, 0, 0, 0], strides=[2, 2],
strides = [2, 2], kernel_shape=[2, 2])
kernel_shape=[2,2]
)
node4 = onnx.helper.make_node( node4 = onnx.helper.make_node('Conv',
'Conv', inputs=['7', '3', '4'],
inputs=['7', '3', '4'], outputs=['8'],
outputs=['8'], dilations=[1, 1],
dilations = [1, 1], strides=[1, 1],
strides = [1, 1], pads=[0, 0, 0, 0])
pads = [0, 0, 0, 0]
)
node5 = onnx.helper.make_node( node5 = onnx.helper.make_node('Relu', inputs=['8'], outputs=['9'])
'Relu',
inputs=['8'],
outputs=['9']
)
node6 = onnx.helper.make_node( node6 = onnx.helper.make_node('MaxPool',
'MaxPool', inputs=['9'],
inputs=['9'], outputs=['10'],
outputs=['10'], pads=[0, 0, 0, 0],
pads = [0, 0, 0, 0], strides=[2, 2],
strides = [2, 2], kernel_shape=[2, 2])
kernel_shape=[2,2]
) return ([node1, node2, node3, node4, node5, node6], [x, y, z, m, n], [out])
return (
[node1, node2, node3, node4, node5, node6],
[x, y, z, m, n],
[out]
)
@onnx_test @onnx_test
def cos_test(): def cos_test():
...@@ -598,6 +527,7 @@ def cos_test(): ...@@ -598,6 +527,7 @@ def cos_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def cosh_test(): def cosh_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [1]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [1])
...@@ -611,33 +541,34 @@ def cosh_test(): ...@@ -611,33 +541,34 @@ def cosh_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def dropout_test(): def dropout_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 2, 2]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 2, 2])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 2, 2]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 2, 2])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Dropout', 'Dropout',
inputs=['0'], inputs=['0'],
outputs=['1'], outputs=['1'],
) )
return ([node], [x], [y])
return ([node], [x], [y])
@onnx_test @onnx_test
def elu_test(): def elu_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3])
node = onnx.helper.make_node( node = onnx.helper.make_node('Elu',
'Elu', inputs=['0'],
inputs=['0'], outputs=['1'],
outputs=['1'], alpha=0.01)
alpha=0.01
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def erf_test(): def erf_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10, 15]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10, 15])
...@@ -651,6 +582,7 @@ def erf_test(): ...@@ -651,6 +582,7 @@ def erf_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def exp_test(): def exp_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
...@@ -664,15 +596,14 @@ def exp_test(): ...@@ -664,15 +596,14 @@ def exp_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def expand_test(): def expand_test():
shape_val = np.array([2, 3, 4, 5]).astype(np.int64) shape_val = np.array([2, 3, 4, 5]).astype(np.int64)
shape_ts = helper.make_tensor( shape_ts = helper.make_tensor(name='shape_tensor',
name = 'shape_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=shape_val.shape,
dims = shape_val.shape, vals=shape_val.flatten().astype(int))
vals = shape_val.flatten().astype(int)
)
shape_const = helper.make_node( shape_const = helper.make_node(
'Constant', 'Constant',
inputs=[], inputs=[],
...@@ -681,40 +612,35 @@ def expand_test(): ...@@ -681,40 +612,35 @@ def expand_test():
) )
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 1, 1]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 1, 1])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4, 5]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4, 5])
node = onnx.helper.make_node(
'Expand',
inputs=['x', 'shape'],
outputs=['y']
)
return ([shape_const,node], [x], [y]) node = onnx.helper.make_node('Expand',
inputs=['x', 'shape'],
outputs=['y'])
return ([shape_const, node], [x], [y])
@onnx_test @onnx_test
def flatten_test(): def flatten_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
y = helper.make_tensor_value_info('2', TensorProto.FLOAT, [6, 20]) y = helper.make_tensor_value_info('2', TensorProto.FLOAT, [6, 20])
y2 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [2, 60]) y2 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [2, 60])
node = onnx.helper.make_node( node = onnx.helper.make_node('Flatten',
'Flatten', inputs=['0'],
inputs=['0'], axis=2,
axis=2, outputs=['2'])
outputs=['2']
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Flatten', inputs=['0'], outputs=['3'])
'Flatten',
inputs=['0'], return ([node, node2], [x], [y, y2])
outputs=['3']
)
return ([node,node2], [x], [y,y2])
@onnx_test @onnx_test
def gather_test(): def gather_test():
x = helper.make_tensor_value_info('data', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('data', TensorProto.FLOAT, [3, 4, 5, 6])
i = helper.make_tensor_value_info('indices', TensorProto.INT32, [2, 3, 4, 5]) i = helper.make_tensor_value_info('indices', TensorProto.INT32,
[2, 3, 4, 5])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4, 5]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node(
...@@ -724,7 +650,8 @@ def gather_test(): ...@@ -724,7 +650,8 @@ def gather_test():
axis=1, axis=1,
) )
return ([node], [x,i], [y]) return ([node], [x, i], [y])
@onnx_test @onnx_test
def gemm_test(): def gemm_test():
...@@ -733,17 +660,16 @@ def gemm_test(): ...@@ -733,17 +660,16 @@ def gemm_test():
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, []) z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [])
a = helper.make_tensor_value_info('3', TensorProto.FLOAT, [7, 11]) a = helper.make_tensor_value_info('3', TensorProto.FLOAT, [7, 11])
node = onnx.helper.make_node( node = onnx.helper.make_node('Gemm',
'Gemm', inputs=['0', '1', '2'],
inputs=['0', '1', '2'], outputs=['3'],
outputs=['3'], alpha=2.0,
alpha=2.0, beta=2.0,
beta=2.0, transA=1,
transA=1, transB=1)
transB=1
) return ([node], [x, y, z], [a])
return ([node], [x,y,z], [a])
@onnx_test @onnx_test
def gemm_ex_test(): def gemm_ex_test():
...@@ -752,16 +678,15 @@ def gemm_ex_test(): ...@@ -752,16 +678,15 @@ def gemm_ex_test():
m3 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [1, 1, 6, 7]) m3 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [1, 1, 6, 7])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [1, 1, 6, 7]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [1, 1, 6, 7])
node = onnx.helper.make_node( node = onnx.helper.make_node('Gemm',
'Gemm', inputs=['1', '2', '3'],
inputs=['1', '2', '3'], outputs=['y'],
outputs=['y'], alpha=0.5,
alpha = 0.5, beta=0.8,
beta = 0.8, transA=1)
transA = 1
) return ([node], [m1, m2, m3], [y])
return ([node], [m1,m2,m3], [y])
@onnx_test @onnx_test
def gemm_ex_brcst_test(): def gemm_ex_brcst_test():
...@@ -770,21 +695,20 @@ def gemm_ex_brcst_test(): ...@@ -770,21 +695,20 @@ def gemm_ex_brcst_test():
m3 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [1, 1, 6, 1]) m3 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [1, 1, 6, 1])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [1, 1, 6, 7]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [1, 1, 6, 7])
node = onnx.helper.make_node( node = onnx.helper.make_node('Gemm',
'Gemm', inputs=['1', '2', '3'],
inputs=['1', '2', '3'], outputs=['y'],
outputs=['y'], alpha=0.5,
alpha = 0.5, beta=0.8,
beta = 0.8, transA=1)
transA = 1
) return ([node], [m1, m2, m3], [y])
return ([node], [m1,m2,m3], [y])
@onnx_test @onnx_test
def globalavgpool_test(): def globalavgpool_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1,3,16,16]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 16, 16])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1,3,1,1]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 1, 1])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'GlobalAveragePool', 'GlobalAveragePool',
...@@ -794,10 +718,11 @@ def globalavgpool_test(): ...@@ -794,10 +718,11 @@ def globalavgpool_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def globalmaxpool_test(): def globalmaxpool_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1,3,16,16]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 16, 16])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1,3,1,1]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 1, 1])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'GlobalMaxPool', 'GlobalMaxPool',
...@@ -807,6 +732,7 @@ def globalmaxpool_test(): ...@@ -807,6 +732,7 @@ def globalmaxpool_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def group_conv_test(): def group_conv_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 4, 16, 16]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 4, 16, 16])
...@@ -820,23 +746,23 @@ def group_conv_test(): ...@@ -820,23 +746,23 @@ def group_conv_test():
outputs=['2'], outputs=['2'],
) )
return ([node], [x,y], [z]) return ([node], [x, y], [z])
@onnx_test @onnx_test
def imagescaler_test(): def imagescaler_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1,3,16,16]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 16, 16])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1,3,16,16]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3, 16, 16])
node = onnx.helper.make_node( node = onnx.helper.make_node('ImageScaler',
'ImageScaler', inputs=['0'],
inputs=['0'], outputs=['1'],
outputs=['1'], bias=[0.01, 0.02, 0.03],
bias=[0.01,0.02,0.03], scale=0.5)
scale=0.5
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def implicit_add_bcast_test(): def implicit_add_bcast_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
...@@ -849,13 +775,15 @@ def implicit_add_bcast_test(): ...@@ -849,13 +775,15 @@ def implicit_add_bcast_test():
outputs=['2'], outputs=['2'],
) )
return ([node], [x,y], [z]) return ([node], [x, y], [z])
@onnx_test @onnx_test
def implicit_pow_bcast_test(): def implicit_pow_bcast_test():
arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 4, 1]) arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 4, 1])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT, [2, 3, 4, 5]) arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT,
[2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Pow', 'Pow',
...@@ -863,13 +791,15 @@ def implicit_pow_bcast_test(): ...@@ -863,13 +791,15 @@ def implicit_pow_bcast_test():
outputs=['out'], outputs=['out'],
) )
return ([node], [arg0,arg1], [arg_out]) return ([node], [arg0, arg1], [arg_out])
@onnx_test @onnx_test
def implicit_sub_bcast_test(): def implicit_sub_bcast_test():
arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [4, 5]) arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [4, 5])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT, [2, 3, 4, 5]) arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT,
[2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Sub', 'Sub',
...@@ -877,22 +807,22 @@ def implicit_sub_bcast_test(): ...@@ -877,22 +807,22 @@ def implicit_sub_bcast_test():
outputs=['out'], outputs=['out'],
) )
return ([node], [arg0,arg1], [arg_out]) return ([node], [arg0, arg1], [arg_out])
@onnx_test @onnx_test
def leaky_relu_test(): def leaky_relu_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3])
node = onnx.helper.make_node( node = onnx.helper.make_node('LeakyRelu',
'LeakyRelu', inputs=['0'],
inputs=['0'], outputs=['1'],
outputs=['1'], alpha=0.01)
alpha=0.01
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def log_test(): def log_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
...@@ -906,37 +836,36 @@ def log_test(): ...@@ -906,37 +836,36 @@ def log_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def logsoftmax_test(): def logsoftmax_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 5, 6]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 5, 6])
node = onnx.helper.make_node( node = onnx.helper.make_node('LogSoftmax',
'LogSoftmax', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axis=1)
axis = 1
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def lrn_test(): def lrn_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 28, 24, 24]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 28, 24, 24])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 28, 24, 24]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 28, 24, 24])
node = onnx.helper.make_node( node = onnx.helper.make_node('LRN',
'LRN', inputs=['0'],
inputs=['0'], size=5,
size=5, alpha=0.0001,
alpha=0.0001, beta=0.75,
beta=0.75, bias=1.0,
bias=1.0, outputs=['1'])
outputs=['1']
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def matmul_bmbm_test(): def matmul_bmbm_test():
m1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 6, 7]) m1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 6, 7])
...@@ -949,7 +878,8 @@ def matmul_bmbm_test(): ...@@ -949,7 +878,8 @@ def matmul_bmbm_test():
outputs=['y'], outputs=['y'],
) )
return ([node], [m1,m2], [y]) return ([node], [m1, m2], [y])
@onnx_test @onnx_test
def matmul_bmv_test(): def matmul_bmv_test():
...@@ -963,7 +893,8 @@ def matmul_bmv_test(): ...@@ -963,7 +893,8 @@ def matmul_bmv_test():
outputs=['y'], outputs=['y'],
) )
return ([node], [m1,m2], [y]) return ([node], [m1, m2], [y])
@onnx_test @onnx_test
def matmul_mv_test(): def matmul_mv_test():
...@@ -977,7 +908,8 @@ def matmul_mv_test(): ...@@ -977,7 +908,8 @@ def matmul_mv_test():
outputs=['y'], outputs=['y'],
) )
return ([node], [m1,m2], [y]) return ([node], [m1, m2], [y])
@onnx_test @onnx_test
def matmul_vbm_test(): def matmul_vbm_test():
...@@ -991,7 +923,8 @@ def matmul_vbm_test(): ...@@ -991,7 +923,8 @@ def matmul_vbm_test():
outputs=['y'], outputs=['y'],
) )
return ([node], [m1,m2], [y]) return ([node], [m1, m2], [y])
@onnx_test @onnx_test
def matmul_vm_test(): def matmul_vm_test():
...@@ -1005,7 +938,8 @@ def matmul_vm_test(): ...@@ -1005,7 +938,8 @@ def matmul_vm_test():
outputs=['y'], outputs=['y'],
) )
return ([node], [m1,m2], [y]) return ([node], [m1, m2], [y])
@onnx_test @onnx_test
def matmul_vv_test(): def matmul_vv_test():
...@@ -1019,7 +953,8 @@ def matmul_vv_test(): ...@@ -1019,7 +953,8 @@ def matmul_vv_test():
outputs=['y'], outputs=['y'],
) )
return ([node], [m1,m2], [y]) return ([node], [m1, m2], [y])
@onnx_test @onnx_test
def max_test(): def max_test():
...@@ -1034,7 +969,8 @@ def max_test(): ...@@ -1034,7 +969,8 @@ def max_test():
outputs=['3'], outputs=['3'],
) )
return ([node], [a,b,c], [y]) return ([node], [a, b, c], [y])
@onnx_test @onnx_test
def min_test(): def min_test():
...@@ -1049,41 +985,41 @@ def min_test(): ...@@ -1049,41 +985,41 @@ def min_test():
outputs=['3'], outputs=['3'],
) )
return ([node], [a,b,c], [y]) return ([node], [a, b, c], [y])
@onnx_test @onnx_test
def no_pad_test(): def no_pad_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 2]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 2])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [2, 2]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [2, 2])
node = onnx.helper.make_node( node = onnx.helper.make_node('Pad',
'Pad', inputs=['0'],
inputs=['0'], pads=[0, 0, 0, 0],
pads=[0,0,0,0], outputs=['1'])
outputs=['1']
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def pad_test(): def pad_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 2]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 2])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [4, 4]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [4, 4])
node = onnx.helper.make_node( node = onnx.helper.make_node('Pad',
'Pad', inputs=['0'],
inputs=['0'], pads=[1, 1, 1, 1],
pads=[1,1,1,1], outputs=['1'])
outputs=['1']
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def pow_test(): def pow_test():
arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [2, 3, 4, 5]) arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [2, 3, 4, 5])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT, [2, 3, 4, 5]) arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT,
[2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Pow', 'Pow',
...@@ -1091,121 +1027,108 @@ def pow_test(): ...@@ -1091,121 +1027,108 @@ def pow_test():
outputs=['out'], outputs=['out'],
) )
return ([node], [arg0, arg1], [arg_out]) return ([node], [arg0, arg1], [arg_out])
@onnx_test @onnx_test
def reducemean_test(): def reducemean_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4])
axes=[2, 3] axes = [2, 3]
node = onnx.helper.make_node( node = onnx.helper.make_node('ReduceMean',
'ReduceMean', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axes=axes,
axes=axes, keepdims=0)
keepdims = 0
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def reducemean_keepdims_test(): def reducemean_keepdims_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 6]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 6])
axes=[2] axes = [2]
node = onnx.helper.make_node( node = onnx.helper.make_node('ReduceMean',
'ReduceMean', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axes=axes,
axes=axes, keepdims=1)
keepdims = 1
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def reducesum_test(): def reducesum_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 1]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 1])
axes=[2] axes = [2]
node = onnx.helper.make_node( node = onnx.helper.make_node('ReduceSum',
'ReduceSum', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axes=axes,
axes=axes, keepdims=0)
keepdims = 0
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def reducesum_multiaxis_test(): def reducesum_multiaxis_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 1]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 1])
axes=[2, 3] axes = [2, 3]
node = onnx.helper.make_node( node = onnx.helper.make_node('ReduceSum',
'ReduceSum', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axes=axes,
axes=axes, keepdims=0)
keepdims = 0
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def reducesum_keepdims_test(): def reducesum_keepdims_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 1]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 4, 1, 1])
axes=[2, 3] axes = [2, 3]
node = onnx.helper.make_node( node = onnx.helper.make_node('ReduceSum',
'ReduceSum', inputs=['x'],
inputs=['x'], outputs=['y'],
outputs=['y'], axes=axes,
axes=axes, keepdims=1)
keepdims = 1
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def reshape_test(): def reshape_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [4, 2, 3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [4, 2, 3])
x_shape = helper.make_tensor_value_info('1', TensorProto.INT64, [2]) x_shape = helper.make_tensor_value_info('1', TensorProto.INT64, [2])
x_shape_list = [3,8] x_shape_list = [3, 8]
y = helper.make_tensor_value_info('2', TensorProto.FLOAT, [3, 8]) y = helper.make_tensor_value_info('2', TensorProto.FLOAT, [3, 8])
y2 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [3, 8]) y2 = helper.make_tensor_value_info('3', TensorProto.FLOAT, [3, 8])
node = onnx.helper.make_node( node = onnx.helper.make_node('Reshape', inputs=['0', '1'], outputs=['2'])
'Reshape',
inputs=['0', '1'],
outputs=['2']
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Reshape',
'Reshape', inputs=['0'],
inputs=['0'], shape=x_shape_list,
shape=x_shape_list, outputs=['3'])
outputs=['3']
) return ([node, node2], [x, x_shape], [y, y2],
[helper.make_tensor('1', TensorProto.INT64, [2], [3, 8])])
return (
[node,node2],
[x, x_shape],
[y,y2],
[helper.make_tensor('1', TensorProto.INT64, [2], [3, 8])]
)
@onnx_test @onnx_test
def reshape_non_standard_test(): def reshape_non_standard_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [2, 3, 4]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [2, 3, 4])
trans_x = helper.make_tensor_value_info('trans_x', TensorProto.FLOAT, [2, 4, 3]) trans_x = helper.make_tensor_value_info('trans_x', TensorProto.FLOAT,
[2, 4, 3])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [4, 3, 2]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [4, 3, 2])
trans = helper.make_node( trans = helper.make_node(
...@@ -1215,14 +1138,13 @@ def reshape_non_standard_test(): ...@@ -1215,14 +1138,13 @@ def reshape_non_standard_test():
perm=[0, 2, 1], perm=[0, 2, 1],
) )
res = onnx.helper.make_node( res = onnx.helper.make_node('Reshape',
'Reshape', inputs=['trans_x'],
inputs=['trans_x'], outputs=['y'],
outputs=['y'], shape=[4, 3, 2])
shape=[4, 3, 2]
) return ([trans, res], [x], [y])
return ([trans,res], [x], [y])
@onnx_test @onnx_test
def shape_test(): def shape_test():
...@@ -1237,6 +1159,7 @@ def shape_test(): ...@@ -1237,6 +1159,7 @@ def shape_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def shape_gather_test(): def shape_gather_test():
values = np.array([1]) values = np.array([1])
...@@ -1245,11 +1168,10 @@ def shape_gather_test(): ...@@ -1245,11 +1168,10 @@ def shape_gather_test():
y = helper.make_tensor_value_info('y', TensorProto.INT64, [3]) y = helper.make_tensor_value_info('y', TensorProto.INT64, [3])
z = helper.make_tensor_value_info('z', TensorProto.FLOAT, [1]) z = helper.make_tensor_value_info('z', TensorProto.FLOAT, [1])
value_tensor = helper.make_tensor( value_tensor = helper.make_tensor(name='const_tensor',
name = 'const_tensor', data_type=TensorProto.INT32,
data_type = TensorProto.INT32, dims=values.shape,
dims = values.shape, vals=values.flatten().astype(int))
vals = values.flatten().astype(int))
node_const = onnx.helper.make_node( node_const = onnx.helper.make_node(
'Constant', 'Constant',
...@@ -1271,7 +1193,8 @@ def shape_gather_test(): ...@@ -1271,7 +1193,8 @@ def shape_gather_test():
axis=0, axis=0,
) )
return ([node_const,node_shape,node_gather], [x], [z]) return ([node_const, node_shape, node_gather], [x], [z])
@onnx_test @onnx_test
def sign_test(): def sign_test():
...@@ -1286,6 +1209,7 @@ def sign_test(): ...@@ -1286,6 +1209,7 @@ def sign_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def sin_test(): def sin_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
...@@ -1299,6 +1223,7 @@ def sin_test(): ...@@ -1299,6 +1223,7 @@ def sin_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def sinh_test(): def sinh_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
...@@ -1312,35 +1237,32 @@ def sinh_test(): ...@@ -1312,35 +1237,32 @@ def sinh_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def slice_test(): def slice_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3, 2]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3, 2])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 2]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 2])
node = onnx.helper.make_node( node = onnx.helper.make_node('Slice',
'Slice', inputs=['0'],
inputs=['0'], axes=[0, 1],
axes=[0, 1], starts=[1, 0],
starts=[1,0], ends=[2, 2],
ends=[2, 2], outputs=['1'])
outputs=['1']
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def softmax_test(): def softmax_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 3])
node = onnx.helper.make_node( node = onnx.helper.make_node('Softmax', inputs=['0'], outputs=['1'])
'Softmax',
inputs=['0'],
outputs=['1']
)
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def sqrt_test(): def sqrt_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10, 15]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10, 15])
...@@ -1354,56 +1276,58 @@ def sqrt_test(): ...@@ -1354,56 +1276,58 @@ def sqrt_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def squeeze_unsqueeze_test(): def squeeze_unsqueeze_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 1, 1, 2, 1]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT,
[1, 3, 1, 1, 2, 1])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 2]) y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 2])
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [1, 1, 3, 1, 2, 1]) z = helper.make_tensor_value_info('2', TensorProto.FLOAT,
[1, 1, 3, 1, 2, 1])
node = onnx.helper.make_node( node = onnx.helper.make_node('Squeeze',
'Squeeze', inputs=['0'],
inputs=['0'], axes=[0, 2, 3, 5],
axes=[0, 2, 3, 5], outputs=['1'])
outputs=['1']
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Unsqueeze',
'Unsqueeze', inputs=['1'],
inputs=['1'], axes=[0, 1, 3, 5],
axes=[0, 1, 3, 5], outputs=['2'])
outputs=['2']
) return ([node, node2], [x], [z])
return ([node,node2], [x], [z])
@onnx_test @onnx_test
def sub_bcast_test(): def sub_bcast_test():
arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 4]) arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT, [3, 4])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT, [2, 3, 4, 5]) arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT,
[2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Sub', 'Sub',
inputs=['0', '1'], inputs=['0', '1'],
outputs=['out'], outputs=['out'],
broadcast = 1, broadcast=1,
axis = 1, axis=1,
) )
return ([node], [arg0,arg1], [arg_out]) return ([node], [arg0, arg1], [arg_out])
@onnx_test @onnx_test
def sub_scalar_test(): def sub_scalar_test():
values = np.array([1]) values = np.array([1])
arg_node = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) arg_node = helper.make_tensor_value_info('0', TensorProto.FLOAT,
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT, [2, 3, 4, 5]) [2, 3, 4, 5])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT,
values_tensor = helper.make_tensor( [2, 3, 4, 5])
name = 'const',
data_type = TensorProto.FLOAT, values_tensor = helper.make_tensor(name='const',
dims = values.shape, data_type=TensorProto.FLOAT,
vals = values.flatten().astype(float) dims=values.shape,
) vals=values.flatten().astype(float))
arg_const = onnx.helper.make_node( arg_const = onnx.helper.make_node(
'Constant', 'Constant',
...@@ -1412,14 +1336,14 @@ def sub_scalar_test(): ...@@ -1412,14 +1336,14 @@ def sub_scalar_test():
value=values_tensor, value=values_tensor,
) )
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Sub', 'Sub',
inputs=['0', 'arg_const'], inputs=['0', 'arg_const'],
outputs=['out'], outputs=['out'],
) )
return ([arg_const,node], [arg_node], [arg_out]) return ([arg_const, node], [arg_node], [arg_out])
@onnx_test @onnx_test
def sum_test(): def sum_test():
...@@ -1435,7 +1359,8 @@ def sum_test(): ...@@ -1435,7 +1359,8 @@ def sum_test():
outputs=['3'], outputs=['3'],
) )
return ([node], [a,b,c], [y]) return ([node], [a, b, c], [y])
@onnx_test @onnx_test
def sum_test(): def sum_test():
...@@ -1450,7 +1375,8 @@ def sum_test(): ...@@ -1450,7 +1375,8 @@ def sum_test():
outputs=['3'], outputs=['3'],
) )
return ([node], [a,b,c], [y]) return ([node], [a, b, c], [y])
@onnx_test @onnx_test
def tan_test(): def tan_test():
...@@ -1458,26 +1384,28 @@ def tan_test(): ...@@ -1458,26 +1384,28 @@ def tan_test():
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [10]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [10])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Tan', 'Tan',
inputs=['x'], inputs=['x'],
outputs=['y'], outputs=['y'],
) )
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def tanh_test(): def tanh_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [1]) x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [1])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [1]) y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [1])
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Tanh', 'Tanh',
inputs=['x'], inputs=['x'],
outputs=['y'], outputs=['y'],
) )
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def transpose_test(): def transpose_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 2, 2, 3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 2, 2, 3])
...@@ -1492,11 +1420,14 @@ def transpose_test(): ...@@ -1492,11 +1420,14 @@ def transpose_test():
return ([node], [x], [y]) return ([node], [x], [y])
@onnx_test @onnx_test
def transpose_gather_test(): def transpose_gather_test():
x = helper.make_tensor_value_info('data', TensorProto.FLOAT, [3, 5, 4, 6]) x = helper.make_tensor_value_info('data', TensorProto.FLOAT, [3, 5, 4, 6])
i = helper.make_tensor_value_info('indices', TensorProto.INT32, [2, 4, 3, 5]) i = helper.make_tensor_value_info('indices', TensorProto.INT32,
y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 2, 3, 4, 5, 4, 5, 6]) [2, 4, 3, 5])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT,
[3, 2, 3, 4, 5, 4, 5, 6])
td = onnx.helper.make_node( td = onnx.helper.make_node(
'Transpose', 'Transpose',
...@@ -1505,12 +1436,10 @@ def transpose_gather_test(): ...@@ -1505,12 +1436,10 @@ def transpose_gather_test():
perm=[0, 2, 1, 3], perm=[0, 2, 1, 3],
) )
ti = onnx.helper.make_node( ti = onnx.helper.make_node('Transpose',
'Transpose', inputs=['indices'],
inputs=['indices'], outputs=['tindices'],
outputs=['tindices'], perm=[0, 2, 1, 3])
perm=[0, 2, 1, 3]
)
node = onnx.helper.make_node( node = onnx.helper.make_node(
'Gather', 'Gather',
...@@ -1519,9 +1448,9 @@ def transpose_gather_test(): ...@@ -1519,9 +1448,9 @@ def transpose_gather_test():
axis=1, axis=1,
) )
return ([td, ti, node], [x, i], [y]) return ([td, ti, node], [x, i], [y])
@onnx_test @onnx_test
def unknown_test(): def unknown_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3, 4, 5])
...@@ -1529,16 +1458,8 @@ def unknown_test(): ...@@ -1529,16 +1458,8 @@ def unknown_test():
z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [2, 3, 4, 5]) z = helper.make_tensor_value_info('2', TensorProto.FLOAT, [2, 3, 4, 5])
a = helper.make_tensor_value_info('3', TensorProto.FLOAT, [2, 3, 4, 5]) a = helper.make_tensor_value_info('3', TensorProto.FLOAT, [2, 3, 4, 5])
node = onnx.helper.make_node( node = onnx.helper.make_node('Unknown', inputs=['0', '1'], outputs=['2'])
'Unknown',
inputs=['0', '1'],
outputs=['2']
)
node2 = onnx.helper.make_node( node2 = onnx.helper.make_node('Unknown', inputs=['2'], outputs=['3'])
'Unknown',
inputs=['2'],
outputs=['3']
)
return ([node,node2], [x,y], [a]) return ([node, node2], [x, y], [a])
\ No newline at end of file
import numpy as np import numpy as np
import tensorflow as tf import tensorflow as tf
def tf_test(op_test): def tf_test(op_test):
def run_test(): def run_test():
g1 = tf.Graph() g1 = tf.Graph()
op_test(g1) op_test(g1)
tf.io.write_graph(g1, '.', '{}.pb'.format(op_test.__name__), as_text=False) tf.io.write_graph(g1,
'.',
'{}.pb'.format(op_test.__name__),
as_text=False)
return run_test return run_test
@tf_test @tf_test
def add_test(g1): def add_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='1')
tf.add(g1_input, g2_input, name = 'add1') tf.add(g1_input, g2_input, name='add1')
@tf_test @tf_test
def add_bcast_test(g1): def add_bcast_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(2,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(2, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(2,1), name = '1') g2_input = tf.placeholder(tf.float32, shape=(2, 1), name='1')
tf.math.add(g1_input, g2_input, name = 'add_bcast1') tf.math.add(g1_input, g2_input, name='add_bcast1')
@tf_test @tf_test
def assert_less_equal_test(g1): def assert_less_equal_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(2,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(2, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(2,3), name = '1') g2_input = tf.placeholder(tf.float32, shape=(2, 3), name='1')
with tf.control_dependencies([tf.assert_less_equal(g1_input, g2_input)]): with tf.control_dependencies(
tf.add(g1_input, g2_input, name = 'add1') [tf.assert_less_equal(g1_input, g2_input)]):
tf.add(g1_input, g2_input, name='add1')
@tf_test @tf_test
def batchmatmul_test(g1): def batchmatmul_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,2,8,4), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 2, 8, 4), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,2,4,8), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 2, 4, 8), name='1')
tf.matmul(g1_input, g2_input, transpose_a=True, transpose_b=True, name='batchmatmul1') tf.matmul(g1_input,
g2_input,
transpose_a=True,
transpose_b=True,
name='batchmatmul1')
@tf_test @tf_test
def batchnorm_test(g1): def batchnorm_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1, 16, 16, 32), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 16, 16, 32), name='0')
g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name = '1') g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name='1')
g1_offset = tf.placeholder(tf.float32, shape=(32), name = '2') g1_offset = tf.placeholder(tf.float32, shape=(32), name='2')
g1_mean = tf.placeholder(tf.float32, shape=(32), name = '3') g1_mean = tf.placeholder(tf.float32, shape=(32), name='3')
g1_variance = tf.placeholder(tf.float32, shape=(32), name = '4') g1_variance = tf.placeholder(tf.float32, shape=(32), name='4')
tf.nn.fused_batch_norm( tf.nn.fused_batch_norm(g1_input,
g1_input, g1_scale, g1_offset, g1_mean, g1_variance, g1_scale,
epsilon=0.00001, is_training=False, name='batchnorm1' g1_offset,
) g1_mean,
g1_variance,
epsilon=0.00001,
is_training=False,
name='batchnorm1')
@tf_test @tf_test
def biasadd_test(g1): def biasadd_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,1,1,500), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 500), name='0')
g2_input = tf.placeholder(tf.float32, shape=(500), name = '1') g2_input = tf.placeholder(tf.float32, shape=(500), name='1')
tf.nn.bias_add(g1_input, g2_input, name = 'bias_add1') tf.nn.bias_add(g1_input, g2_input, name='bias_add1')
@tf_test @tf_test
def cast_test(g1): def cast_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.cast(g1_input, dtype=tf.int32, name='cast1') tf.cast(g1_input, dtype=tf.int32, name='cast1')
@tf_test @tf_test
def concat_test(g1): def concat_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(4,7,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(4, 7, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(4,2,3), name = '1') g2_input = tf.placeholder(tf.float32, shape=(4, 2, 3), name='1')
tf.concat([g1_input, g2_input], axis=1, name = 'concat1') tf.concat([g1_input, g2_input], axis=1, name='concat1')
@tf_test @tf_test
def const_test(g1): def const_test(g1):
with g1.as_default(): with g1.as_default():
tf.constant(1.0, dtype=tf.float32 ,name='constant1') tf.constant(1.0, dtype=tf.float32, name='constant1')
@tf_test @tf_test
def conv_test(g1): def conv_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,16,16,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 16, 16, 3), name='0')
g1_weights = tf.constant(value=1.0, dtype=tf.float32, shape=(3,3,3,32), name = '1') g1_weights = tf.constant(value=1.0,
tf.nn.conv2d(g1_input, g1_weights, [1,1,1,1], "SAME", name = 'conv1') dtype=tf.float32,
shape=(3, 3, 3, 32),
name='1')
tf.nn.conv2d(g1_input, g1_weights, [1, 1, 1, 1], "SAME", name='conv1')
@tf_test @tf_test
def depthwiseconv_test(g1): def depthwiseconv_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,16,16,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 16, 16, 3), name='0')
g1_weights = tf.constant(value=1.0, dtype=tf.float32, shape=(3,3,3,1), name = '1') g1_weights = tf.constant(value=1.0,
tf.nn.depthwise_conv2d_native(g1_input, g1_weights, [1,1,1,1], "SAME", name = 'depthwiseconv1') dtype=tf.float32,
shape=(3, 3, 3, 1),
name='1')
tf.nn.depthwise_conv2d_native(g1_input,
g1_weights, [1, 1, 1, 1],
"SAME",
name='depthwiseconv1')
@tf_test @tf_test
def expanddims_test(g1): def expanddims_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(2,3,4), name = '0') g1_input = tf.placeholder(tf.float32, shape=(2, 3, 4), name='0')
tf.expand_dims(g1_input, axis=-1, name='expanddims_neg') tf.expand_dims(g1_input, axis=-1, name='expanddims_neg')
@tf_test @tf_test
def gather_test(g1): def gather_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(2,4), name = '0') g1_input = tf.placeholder(tf.float32, shape=(2, 4), name='0')
tf.gather(g1_input, [1,1], axis=1, name='gather1') tf.gather(g1_input, [1, 1], axis=1, name='gather1')
@tf_test @tf_test
def identity_test(g1): def identity_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.identity(g1_input, 'identity') tf.identity(g1_input, 'identity')
@tf_test @tf_test
def matmul_test(g1): def matmul_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(8,4), name = '0') g1_input = tf.placeholder(tf.float32, shape=(8, 4), name='0')
g2_input = tf.placeholder(tf.float32, shape=(4,8), name = '1') g2_input = tf.placeholder(tf.float32, shape=(4, 8), name='1')
tf.matmul(g1_input, g2_input, transpose_a=True, transpose_b=True, name='matmul1') tf.matmul(g1_input,
g2_input,
transpose_a=True,
transpose_b=True,
name='matmul1')
@tf_test @tf_test
def mean_test(g1): def mean_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.math.reduce_mean( tf.math.reduce_mean(g1_input, axis=(2, 3), keepdims=True, name='mean1')
g1_input, tf.math.reduce_mean(g1_input,
axis=(2,3), axis=(2, 3),
keepdims=True, keepdims=False,
name='mean1' name='mean2')
)
tf.math.reduce_mean(
g1_input,
axis=(2,3),
keepdims=False,
name='mean2'
)
@tf_test @tf_test
def mean_test_nhwc(g1): def mean_test_nhwc(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,16,16,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 16, 16, 3), name='0')
tf.math.reduce_mean( tf.math.reduce_mean(g1_input, axis=(1, 2), keepdims=True, name='mean1')
g1_input, tf.math.reduce_mean(g1_input,
axis=(1,2), axis=(1, 2),
keepdims=True, keepdims=False,
name='mean1' name='mean2')
)
tf.math.reduce_mean(
g1_input,
axis=(1,2),
keepdims=False,
name='mean2'
)
@tf_test @tf_test
def mul_test(g1): def mul_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,1,1,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 16), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,1,1,16), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 16), name='1')
tf.multiply(g1_input, g2_input, name='mul1') tf.multiply(g1_input, g2_input, name='mul1')
@tf_test @tf_test
def pack_test(g1): def pack_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(2), name = '0') g1_input = tf.placeholder(tf.float32, shape=(2), name='0')
g2_input = tf.placeholder(tf.float32, shape=(2), name = '1') g2_input = tf.placeholder(tf.float32, shape=(2), name='1')
g3_input = tf.placeholder(tf.float32, shape=(2), name = '2') g3_input = tf.placeholder(tf.float32, shape=(2), name='2')
tf.stack([g1_input, g2_input, g3_input], axis=1, name = 'pack1') tf.stack([g1_input, g2_input, g3_input], axis=1, name='pack1')
@tf_test @tf_test
def pack_test_nhwc(g1): def pack_test_nhwc(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,1,1,2), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 2), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,1,1,2), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 2), name='1')
g3_input = tf.placeholder(tf.float32, shape=(1,1,1,2), name = '2') g3_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 2), name='2')
tf.stack([g1_input, g2_input, g3_input], axis=3, name = 'pack1') tf.stack([g1_input, g2_input, g3_input], axis=3, name='pack1')
@tf_test @tf_test
def pooling_test(g1): def pooling_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,16,16,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 16, 16, 3), name='0')
tf.nn.avg_pool( tf.nn.avg_pool(value=g1_input,
value=g1_input, ksize=(1, 2, 2, 1),
ksize=(1,2,2,1), strides=(1, 2, 2, 1),
strides=(1,2,2,1), padding='VALID',
padding='VALID', data_format='NHWC',
data_format='NHWC', name='avg_pooling')
name='avg_pooling' tf.nn.max_pool(value=g1_input,
) ksize=(1, 2, 2, 1),
tf.nn.max_pool( strides=(1, 2, 2, 1),
value=g1_input, padding='VALID',
ksize=(1,2,2,1), data_format='NHWC',
strides=(1,2,2,1), name='max_pooling')
padding='VALID',
data_format='NHWC',
name='max_pooling'
)
@tf_test @tf_test
def pow_test(g1): def pow_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='1')
tf.pow(g1_input, g2_input, name = 'pow1') tf.pow(g1_input, g2_input, name='pow1')
@tf_test @tf_test
def relu_test(g1): def relu_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.nn.relu(g1_input, 'relu') tf.nn.relu(g1_input, 'relu')
@tf_test @tf_test
def relu6_test(g1): def relu6_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.nn.relu6(g1_input, 'relu6') tf.nn.relu6(g1_input, 'relu6')
@tf_test @tf_test
def reshape_test(g1): def reshape_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(16), name='0')
tf.reshape(g1_input, (1,1,1,16), 'reshape') tf.reshape(g1_input, (1, 1, 1, 16), 'reshape')
@tf_test @tf_test
def rsqrt_test(g1): def rsqrt_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.math.rsqrt(g1_input, 'rsqrt') tf.math.rsqrt(g1_input, 'rsqrt')
@tf_test @tf_test
def slice_test(g1): def slice_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(5,10), name = '0') g1_input = tf.placeholder(tf.float32, shape=(5, 10), name='0')
tf.slice(g1_input, [1, 0], [2, -1], name = 'slice1') tf.slice(g1_input, [1, 0], [2, -1], name='slice1')
@tf_test @tf_test
def softmax_test(g1): def softmax_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3), name='0')
tf.nn.softmax(g1_input, name='softmax') tf.nn.softmax(g1_input, name='softmax')
@tf_test @tf_test
def sqdiff_test(g1): def sqdiff_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='1')
tf.squared_difference(g1_input, g2_input, name = 'sqdiff') tf.squared_difference(g1_input, g2_input, name='sqdiff')
@tf_test @tf_test
def squeeze_test(g1): def squeeze_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,2,3,1), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 2, 3, 1), name='0')
tf.squeeze(g1_input, name='squeeze') tf.squeeze(g1_input, name='squeeze')
@tf_test @tf_test
def stopgradient_test(g1): def stopgradient_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.stop_gradient(g1_input, 'stopgradient') tf.stop_gradient(g1_input, 'stopgradient')
@tf_test @tf_test
def stridedslice_test(g1): def stridedslice_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,1,1,10), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 1, 1, 10), name='0')
tf.strided_slice(g1_input, [0, 0, 0, 0], [1, 1, 1, 5], [1,1,1,1], shrink_axis_mask=2, name = 'stridedslice1') tf.strided_slice(g1_input, [0, 0, 0, 0], [1, 1, 1, 5], [1, 1, 1, 1],
shrink_axis_mask=2,
name='stridedslice1')
@tf_test @tf_test
def stridedslice_masks_test(g1): def stridedslice_masks_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,3,10), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 3, 10), name='0')
tf.strided_slice(g1_input, [0, 1, 1, 0], [0, 0, 0, 0], [1,1,1,1], begin_mask=9, end_mask=15, name = 'stridedslice1') tf.strided_slice(g1_input, [0, 1, 1, 0], [0, 0, 0, 0], [1, 1, 1, 1],
begin_mask=9,
end_mask=15,
name='stridedslice1')
@tf_test @tf_test
def sub_test(g1): def sub_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='0')
g2_input = tf.placeholder(tf.float32, shape=(1,2,2,3), name = '1') g2_input = tf.placeholder(tf.float32, shape=(1, 2, 2, 3), name='1')
tf.subtract(g1_input, g2_input, name = 'sub1') tf.subtract(g1_input, g2_input, name='sub1')
@tf_test @tf_test
def tanh_test(g1): def tanh_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.tanh(g1_input, 'tanh') tf.tanh(g1_input, 'tanh')
@tf_test @tf_test
def transpose_test(g1): def transpose_test(g1):
with g1.as_default(): with g1.as_default():
g1_input = tf.placeholder(tf.float32, shape=(1,3,16,16), name = '0') g1_input = tf.placeholder(tf.float32, shape=(1, 3, 16, 16), name='0')
tf.transpose(g1_input, perm=[0,2,3,1], name = 'transpose') tf.transpose(g1_input, perm=[0, 2, 3, 1], name='transpose')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment