[Frontend]Add Paddle Op Conversion Tests (#6982)

* fix paddle model test

* enable paddle ops tests

* fix code style

* remove useless log in paddle scripts
This commit is contained in:
Zhang Yi 2021-08-11 14:22:04 +08:00 committed by GitHub
parent 8a200d60f3
commit e36f42b205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 2725 additions and 15 deletions

View File

@ -26,11 +26,147 @@ static const std::vector<std::string> models{
std::string("assign_value_fp32"),
std::string("assign_value_int32"),
std::string("assign_value_int64"),
std::string("avgAdaptivePool2D_test1"),
std::string("avgPool_test1"),
std::string("avgPool_test10"),
std::string("avgPool_test11"),
std::string("avgPool_test2"),
std::string("avgPool_test3"),
std::string("avgPool_test4"),
std::string("avgPool_test5"),
// avgPool_test6<nchw support is disabled now>,
std::string("avgPool_test7"),
std::string("avgPool_test8"),
std::string("avgPool_test9"),
std::string("batch_norm_nchw"),
std::string("batch_norm_nhwc"),
std::string("bilinear_downsample_false_0"),
std::string("bilinear_downsample_false_1"),
std::string("bilinear_downsample_true_0"),
std::string("bilinear_upsample_false_0"),
std::string("bilinear_upsample_false_1"),
std::string("bilinear_upsample_scales"),
std::string("bilinear_upsample_scales2"),
std::string("bilinear_upsample_true_0"),
std::string("bmm"),
std::string("clip"),
std::string("conv2d_dilation_assymetric_pads_strides"),
std::string("conv2d_SAME_padding"),
std::string("conv2d_strides_assymetric_padding"),
std::string("conv2d_strides_no_padding"),
std::string("conv2d_strides_padding"),
std::string("conv2d_transpose_dilation_assymetric_pads_strides"),
// conv2d_transpose_SAME_padding(PDPD outputs wrong results),
std::string("conv2d_transpose_strides_assymetric_padding"),
std::string("conv2d_transpose_strides_no_padding"),
std::string("conv2d_transpose_strides_padding"),
std::string("conv2d_transpose_VALID_padding"),
std::string("conv2d_VALID_padding"),
std::string("depthwise_conv2d_convolution"),
std::string("depthwise_conv2d_transpose_convolution"),
std::string("dropout"),
std::string("dropout_upscale_in_train"),
std::string("elementwise_add1"),
std::string("elementwise_div1"),
std::string("elementwise_max1"),
std::string("elementwise_min1"),
std::string("elementwise_mul1"),
std::string("elementwise_pow1"),
std::string("elementwise_sub1"),
std::string("equal"),
std::string("expand_v2"),
std::string("expand_v2_tensor"),
std::string("expand_v2_tensor_list"),
std::string("fill_constant"),
std::string("fill_constant_batch_size_like"),
std::string("fill_constant_int32"),
std::string("fill_constant_int64"),
std::string("fill_constant_tensor"),
std::string("fill_constant_shape_tensor"),
std::string("fill_constant_shape_tensor_list"),
std::string("flatten_contiguous_range_test1"),
// greater_equal_big_int64(failure due to CPU inference),
std::string("greater_equal_float32"),
std::string("greater_equal_int32"),
std::string("greater_equal_int64"),
std::string("hard_sigmoid"),
std::string("hard_swish"),
std::string("leaky_relu"),
std::string("log"),
std::string("logical_not"),
std::string("matmul_xt"),
std::string("matmul_xt_yt"),
std::string("matmul_yt"),
std::string("maxAdaptivePool2D_test1"),
std::string("maxPool_test1"),
std::string("maxPool_test10"),
std::string("maxPool_test11"),
std::string("maxPool_test2"),
std::string("maxPool_test3"),
std::string("maxPool_test4"),
std::string("maxPool_test5"),
// maxPool_test6(nchw support is disabled now),
std::string("maxPool_test7"),
std::string("maxPool_test8"),
std::string("maxPool_test9"),
std::string("mul_fp32"),
std::string("nearest_downsample_false_0"),
std::string("nearest_downsample_false_1"),
std::string("nearest_upsample_false_0"),
std::string("nearest_upsample_false_1"),
std::string("pad3d_test1"),
std::string("pad3d_test2"),
std::string("pad3d_test3"),
// pad3d_test4,
std::string("pow_float32"),
std::string("pow_int32"),
std::string("pow_int64"),
// pow_int64_out_of_range(out of range of OV int64),
std::string("pow_y_tensor"),
std::string("range0"),
std::string("range1"),
std::string("range2"),
std::string("relu"),
};
std::string("relu6"),
std::string("relu6_1"),
std::string("reshape"),
std::string("reshape_tensor"),
std::string("reshape_tensor_list"),
std::string("rnn_lstm_layer_1_bidirectional"),
std::string("rnn_lstm_layer_1_forward"),
std::string("rnn_lstm_layer_2_bidirectional"),
std::string("rnn_lstm_layer_2_forward"),
std::string("scale_bias_after_float32"),
std::string("scale_bias_after_int32"),
std::string("scale_bias_after_int64"),
std::string("scale_bias_before_float32"),
std::string("scale_bias_before_int32"),
std::string("scale_bias_before_int64"),
std::string("scale_tensor_bias_after"),
std::string("scale_tensor_bias_before"),
std::string("shape"),
std::string("sigmoid"),
std::string("slice"),
std::string("slice_1d"),
std::string("softmax"),
std::string("softmax_minus"),
std::string("split_test1"),
std::string("split_test2"),
std::string("split_test3"),
std::string("split_test4"),
std::string("split_test5"),
std::string("split_test6"),
std::string("split_test_dim_int32"),
std::string("split_test_dim_int64"),
std::string("split_test_list"),
std::string("split_test_list_tensor"),
std::string("squeeze"),
std::string("squeeze_null_axes"),
std::string("unsqueeze"),
std::string("yolo_box_clip_box"),
std::string("yolo_box_default"),
std::string("yolo_box_scale_xy"),
std::string("yolo_box_uneven_wh")};
INSTANTIATE_TEST_SUITE_P(
PDPDFuzzyOpTest,

View File

@ -27,8 +27,6 @@ def pdpd_assign_value(name, test_x):
saveModel(name, exe, feedkeys=['x'], fetchlist=[result], inputs=[test_x], outputs=[outs[0]], target_dir=sys.argv[1])
print(outs[0])
def compare():

View File

@ -0,0 +1,39 @@
import numpy as np
from save_model import saveModel
import sys
def pdpd_bmm(x1, x2):
import paddle as pdpd
pdpd.enable_static()
node_x1 = pdpd.static.data(name='x1', shape=x1.shape, dtype=x1.dtype)
node_x2 = pdpd.static.data(name='x2', shape=x2.shape, dtype=x2.dtype)
bmm_node = pdpd.bmm(node_x1, node_x2)
result = pdpd.static.nn.batch_norm(bmm_node, use_global_stats=True)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x1': x1, 'x2': x2},
fetch_list=[result])
saveModel("bmm", exe, feedkeys=['x1', 'x2'], fetchlist=[result],
inputs=[x1, x2], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
if __name__ == "__main__":
input1 = np.array([[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]).astype(np.float32)
input2 = np.ones([1, 5, 7]).astype('float32')
pdpd_result = pdpd_bmm(input1, input2)

View File

@ -0,0 +1,145 @@
from save_model import saveModel
import numpy as np
import paddle as pdpd
import sys
pdpd.enable_static()
def run_and_save_model(input_x, name, feed, fetch_list, main_prog, start_prog):
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
exe.run(start_prog)
outs = exe.run(
feed={'x': input_x},
fetch_list=fetch_list,
program=main_prog)
with pdpd.static.program_guard(main_prog, start_prog):
saveModel(name, exe, feedkeys=['x'], fetchlist=fetch_list, inputs=[input_x],
outputs=[outs[0]], target_dir=sys.argv[1])
def pdpd_conv2d(input_x, name, input_shape, kernel, dilation, padding, stride, groups=1, use_cudnn=True):
main_program = pdpd.static.Program()
startup_program = pdpd.static.Program()
with pdpd.static.program_guard(main_program, startup_program):
data = pdpd.static.data(name='x', shape=input_shape, dtype='float32')
weight_attr = pdpd.ParamAttr(name="conv2d_weight", initializer=pdpd.nn.initializer.Assign(kernel))
conv2d = pdpd.static.nn.conv2d(input=data, num_filters=kernel.shape[0], filter_size=kernel.shape[2:4],
padding=padding, param_attr=weight_attr, dilation=dilation, stride=stride, groups=groups, use_cudnn=use_cudnn)
run_and_save_model(input_x, name, data, conv2d, main_program, startup_program)
if __name__ == "__main__":
test_cases =[
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_SAME_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": "SAME",
"stride" : 2,
},
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_VALID_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": "VALID",
"stride" : 2,
},
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_strides_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": 1,
"stride" : 2,
},
{ "input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_strides_no_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": 0,
"stride" : 2,
},
{ "input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_strides_assymetric_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": [1,1,0,1],
"stride" : 2,
},
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_dilation_assymetric_pads_strides",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": [1, 1, 1, 2],
"stride" : [3, 1],
},
{
"input_x": np.arange(27).astype(np.float32).reshape([1, 3, 3, 3]),
"name": "depthwise_conv2d_convolution",
"input_shape": [1, 3, 3, 3],
"kernel": np.ones([3, 1, 3, 3]).astype(np.float32),
"dilation": 1,
"padding": 1,
"stride": 1,
"groups": 3,
"use_cudnn": False
}
]
for test in test_cases:
pdpd_conv2d(test['input_x'], test['name'], test["input_shape"],
test['kernel'], test['dilation'],
test['padding'],
test['stride'],
1 if "groups" not in test else test['groups'],
True if "use_cudnn" not in test else test['use_cudnn'])

View File

@ -0,0 +1,144 @@
import numpy as np
import paddle as pdpd
pdpd.enable_static()
from save_model import saveModel
import sys
def run_and_save_model(input_x, name, feed, fetch_list, main_prog, start_prog):
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
exe.run(start_prog)
outs = exe.run(
feed={'x': input_x},
fetch_list=fetch_list,
program=main_prog)
with pdpd.static.program_guard(main_prog, start_prog):
saveModel(name, exe, feedkeys=['x'], fetchlist=fetch_list, inputs=[input_x],
outputs=[outs[0]], target_dir=sys.argv[1])
def pdpd_conv2d_transpose(input_x, name, input_shape, kernel, dilation, padding, stride, groups=1, use_cudnn=True):
main_program = pdpd.static.Program()
startup_program = pdpd.static.Program()
with pdpd.static.program_guard(main_program, startup_program):
data = pdpd.static.data(name='x', shape=input_shape, dtype='float32')
weight_attr = pdpd.ParamAttr(name="conv2d_weight", initializer=pdpd.nn.initializer.Assign(kernel))
conv2d = pdpd.static.nn.conv2d_transpose(input=data, num_filters=kernel.shape[0], filter_size=kernel.shape[2:4],
padding=padding, param_attr=weight_attr, dilation=dilation, stride=stride, groups=groups, use_cudnn=use_cudnn)
run_and_save_model(input_x, name, data, conv2d, main_program, startup_program)
if __name__ == "__main__":
test_cases =[
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_transpose_SAME_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": "SAME",
"stride" : 2,
},
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_transpose_VALID_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": "VALID",
"stride" : 2,
},
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_transpose_strides_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": 1,
"stride" : 2,
},
{ "input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_transpose_strides_no_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": 0,
"stride" : 2,
},
{ "input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_transpose_strides_assymetric_padding",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": [1,1,0,1],
"stride" : 2,
},
{
"input_x": np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor
[5., 6., 7., 8., 9.],
[10., 11., 12., 13., 14.],
[15., 16., 17., 18., 19.],
[20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29.],
[30., 31., 32., 33., 34.,]]]]).astype(np.float32),
"name": "conv2d_transpose_dilation_assymetric_pads_strides",
"input_shape": [1, 1, 7, 5],
"kernel": np.array([[[[1., 1., 1.],[1., 1., 1.],[1., 1., 1.]]]]).astype(np.float32),
"dilation": 1,
"padding": [1, 1, 1, 2],
"stride" : [3, 1],
},
{
"input_x": np.arange(27).astype(np.float32).reshape([1, 3, 3, 3]),
"name": "depthwise_conv2d_transpose_convolution",
"input_shape": [1, 3, 3, 3],
"kernel": np.ones([3, 1, 3, 3]).astype(np.float32),
"dilation": 1,
"padding": 1,
"stride": 1,
"groups": 3,
"use_cudnn": False
}
]
for test in test_cases:
pdpd_conv2d_transpose(test['input_x'], test['name'], test["input_shape"],
test['kernel'], test['dilation'],
test['padding'],
test['stride'],
1 if "groups" not in test else test['groups'],
True if "use_cudnn" not in test else test['use_cudnn'])

View File

@ -0,0 +1,47 @@
#
# pool2d paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def pdpd_dropout(name : str, x, p, pdpd_attrs):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
out = pdpd.nn.functional.dropout(x=node_x, p=p, training=pdpd_attrs['training'], mode=pdpd_attrs['mode'])
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x],
outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
p=0.5
data = np.random.random(size=(3, 10, 3, 7)).astype('float32')
pdpd_attrs = {
'training' : False,
'mode' : "downscale_in_infer"
}
pdpd_attrs2 = {
'training' : False,
'mode' : "upscale_in_train"
}
pdpd_dropout("dropout", data, p, pdpd_attrs)
pdpd_dropout("dropout_upscale_in_train", data, p, pdpd_attrs2)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,179 @@
#
# elementwise paddle model generator
#
import numpy as np
import sys
from save_model import saveModel
def elementwise_add(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=in_dtype)
node_y = pdpd.static.data(name='y', shape=y.shape, dtype=in_dtype)
out = pdpd.fluid.layers.nn.elementwise_add(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def elementwise_sub(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=in_dtype)
node_y = pdpd.static.data(name='y', shape=y.shape, dtype=in_dtype)
out = pdpd.fluid.layers.nn.elementwise_sub(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def elementwise_div(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
node_y = pdpd.static.data(name = 'y', shape = y.shape, dtype = in_dtype)
out = pdpd.fluid.layers.nn.elementwise_div(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def elementwise_mul(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
node_y = pdpd.static.data(name = 'y', shape = y.shape, dtype = in_dtype)
out = pdpd.fluid.layers.nn.elementwise_mul(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def elementwise_min(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
node_y = pdpd.static.data(name = 'y', shape = y.shape, dtype = in_dtype)
out = pdpd.fluid.layers.nn.elementwise_min(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def elementwise_max(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
node_y = pdpd.static.data(name = 'y', shape = y.shape, dtype = in_dtype)
out = pdpd.fluid.layers.nn.elementwise_max(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def elementwise_pow(name : str, x, y, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
node_y = pdpd.static.data(name = 'y', shape = y.shape, dtype = in_dtype)
out = pdpd.fluid.layers.nn.elementwise_pow(node_x, node_y)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
in_dtype = 'float32'
data_x = np.array([2, 3, 4]).astype(in_dtype)
data_y = np.array([1, 5, 2]).astype(in_dtype)
elementwise_add("elementwise_add1", data_x, data_y, in_dtype)
elementwise_sub("elementwise_sub1", data_x, data_y, in_dtype)
elementwise_div("elementwise_div1", data_x, data_y, in_dtype)
elementwise_mul("elementwise_mul1", data_x, data_y, in_dtype)
elementwise_min("elementwise_min1", data_x, data_y, in_dtype)
elementwise_max("elementwise_max1", data_x, data_y, in_dtype)
elementwise_pow("elementwise_pow1", data_x, data_y, in_dtype)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,43 @@
#
# pool2d paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def equal(name : str, x, y):
import paddle as pdpd
pdpd.enable_static()
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
node_y = pdpd.static.data(name='y', shape=y.shape, dtype='float32')
out = pdpd.equal(node_x, node_y)
out = pdpd.cast(out, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out],
inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
import paddle as pdpd
data_x = np.array([[[[-1, 0, 1]], [[2, 3, 4]]]]).astype(np.float32)
data_y = np.array([[[[2, 0, 3]], [[3, 1, 4]]]]).astype(np.float32)
equal("equal", data_x, data_y)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,71 @@
#
# expand_v2 paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
data_type = 'float32'
def expand_v2(name:str, x, shape:list):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.expand(node_x, shape=shape, name='expand_v2')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def expand_v2_tensor(name:str, x, out_shape, use_tensor_in_list):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
if use_tensor_in_list:
out_shape[0] = pdpd.assign(np.array((out_shape[0],)).astype('int32'))
out = pdpd.expand(node_x, shape=out_shape, name='expand_v2')
else:
out_shape = np.array(out_shape).astype('int32')
node_shape = pdpd.assign(out_shape, output=None)
out = pdpd.expand(node_x, shape=node_shape, name='expand_v2')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data = np.random.rand(1, 1, 6).astype(data_type)
expand_v2("expand_v2", data, [2, 3, -1])
expand_v2_tensor("expand_v2_tensor", data, [2, 3, -1], False)
expand_v2_tensor("expand_v2_tensor_list", data, [2, 3, -1], True)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,97 @@
#
# fill_const paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def fill_constant(name : str, shape : list, dtype, value):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
x1 = pdpd.fluid.layers.fill_constant(shape=shape, value=value, dtype=dtype, name='fill_constant')
x2 = pdpd.fluid.layers.fill_constant(shape=shape, value=value, dtype=dtype, name='fill_constant')
out = pdpd.add(pdpd.cast(x1, np.float32), pdpd.cast(x2, np.float32))
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
fetch_list=[out])
saveModel(name, exe, feedkeys=[], fetchlist=[out], inputs=[], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def fill_constant_tensor(name : str, shape : list, dtype, value):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_value = pdpd.static.data(name='value', shape=[1], dtype=dtype)
x1 = pdpd.fluid.layers.fill_constant(shape=shape, value=node_value, dtype=dtype, name='fill_constant1')
out = pdpd.cast(x1, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={"value": value},
fetch_list=[out])
saveModel(name, exe, feedkeys=["value"], fetchlist=[out], inputs=[np.array([value]).astype(dtype)], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def fill_constant_shape_tensor(name : str, shape, dtype, value):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_shape = pdpd.fluid.layers.fill_constant(shape=[2], value=shape, dtype='int32', name='shape')
x1 = pdpd.fluid.layers.fill_constant(shape=node_shape, value=value, dtype=dtype, name='fill_constant')
out = pdpd.cast(x1, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
fetch_list=[out])
saveModel(name, exe, feedkeys=[], fetchlist=[out], inputs=[], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def fill_constant_shape_tensor_list(name : str, shape: list, dtype, value):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_shape = pdpd.fluid.layers.fill_constant(shape=[1], value=shape, dtype='int32', name='shape')
x1 = pdpd.fluid.layers.fill_constant(shape=[2, node_shape], value=value, dtype=dtype, name='fill_constant')
out = pdpd.cast(x1, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
fetch_list=[out])
saveModel(name, exe, feedkeys=[], fetchlist=[out], inputs=[], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
fill_constant("fill_constant", [2, 3, 4], 'float32', 0.03)
fill_constant("fill_constant_int32", [2, 3, 4], "int32", 2)
fill_constant("fill_constant_int64", [2, 3, 4], "int64", 4)
fill_constant_tensor("fill_constant_tensor", [2, 3, 4], 'float32', 0.05)
fill_constant_shape_tensor("fill_constant_shape_tensor", 2, 'float32', 0.05)
fill_constant_shape_tensor_list("fill_constant_shape_tensor_list", 2, 'float32', 0.05)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,39 @@
#
# fill_constant_batch_size_like paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
data_type = 'float32'
def fill_constant_batch_size_like(name : str, x, shape, dtype, value, input_dim_idx=0, output_dim_idx=0):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
like = pdpd.static.data(name='x', shape=x.shape, dtype = data_type)
out = pdpd.fluid.layers.fill_constant_batch_size_like(input=like, shape=shape, \
value=value, dtype=dtype, \
output_dim_idx=output_dim_idx, input_dim_idx=input_dim_idx)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
x = np.random.rand(4, 3, 2).astype(data_type)
fill_constant_batch_size_like("fill_constant_batch_size_like", \
x, [1, -1, 3], data_type, 0.03, 2, 1)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,38 @@
#
# generate_flatten_contiguous_range paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def generate_flatten_contiguous_range(name : str, x, start_axis, stop_axis, in_dtype):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
out = pdpd.flatten(node_x, start_axis, stop_axis)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
# TODO: more type
in_dtype = 'float32'
data = np.random.randn(3, 2, 5, 4).astype(in_dtype)
start_axis = 1
stop_axis = 2
generate_flatten_contiguous_range("flatten_contiguous_range_test1", data, start_axis, stop_axis, in_dtype)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,60 @@
#
# greater_equal paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def greater_equal(name : str, x, y, data_type, cast_to_fp32=False):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='input_x', shape=x.shape, dtype=data_type)
node_y = pdpd.static.data(name='input_y', shape=y.shape, dtype=data_type)
out = pdpd.fluid.layers.greater_equal(x=node_x, y=node_y, name='greater_equal')
# FuzzyTest framework doesn't support boolean so cast to fp32/int32
if cast_to_fp32:
data_type = "float32"
out = pdpd.cast(out, data_type)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'input_x': x, 'input_y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['input_x', 'input_y'], fetchlist=[out],
inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
test_cases = [
"float32",
"int32",
"int64"
]
for test in test_cases:
x = np.array([0, 1, 2, 3]).astype(test)
y = np.array([1, 0, 2, 4]).astype(test)
if test == "int64":
greater_equal("greater_equal_" + test, x, y, test, True)
else:
greater_equal("greater_equal_" + test, x, y, test, False)
x = np.array([5000000000]).astype("int64")
y = np.array([2000000000]).astype("int64")
greater_equal("greater_equal_big_int64", x, y, test)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,40 @@
#
# hard_sigmoid paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def hard_sigmoid(name: str, x, slope: float = 0.2, offset: float = 0.5, data_type='float32'):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype = data_type)
out = pdpd.fluid.layers.hard_sigmoid(node_x, slope=slope, offset=offset, name='hard_sigmoid')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data_type = 'float32'
data = np.array([0, 1, 2, 3, 4, 5, 6, -10]).astype(data_type)
hard_sigmoid("hard_sigmoid", data, 0.1, 0.6, data_type)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,39 @@
#
# sigmoid paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def hard_swish(name: str, x, threshold=6.0, scale=6.0, offset=3.0, data_type='float32'):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.hard_swish(node_x, threshold=threshold, scale=scale, offset=offset, name='hard_swish')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data_type = 'float32'
data = np.array([-6, 1, 6]).astype(data_type)
hard_swish("hard_swish", data, data_type='float32')
if __name__ == "__main__":
main()

View File

@ -0,0 +1,188 @@
import numpy as np
import paddle as pdpd
from paddle.nn.functional import interpolate
from save_model import saveModel
import sys
pdpd.enable_static()
def run_and_save_model(input_x, name, feed, fetch_list, main_prog, start_prog):
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
exe.run(start_prog)
outs = exe.run(
feed={'x': input_x},
fetch_list=fetch_list,
program=main_prog)
with pdpd.static.program_guard(main_prog, start_prog):
saveModel(name, exe, feedkeys=['x'], fetchlist=fetch_list, inputs=[input_x],
outputs=[outs[0]], target_dir=sys.argv[1])
return outs
def pdpd_interpolate(x, sizes=None, scale_factor=None, mode='nearest', align_corners=True,
align_mode=0, data_format='NCHW', name=None):
pdpd.enable_static()
main_program = pdpd.static.Program()
startup_program = pdpd.static.Program()
with pdpd.static.program_guard(main_program, startup_program):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
interp = interpolate(node_x, size=sizes, scale_factor=scale_factor,
mode=mode, align_corners=align_corners, align_mode=align_mode,
data_format=data_format, name=name)
out = pdpd.static.nn.batch_norm(interp, use_global_stats=True, epsilon=0)
outs = run_and_save_model(x, name, node_x, out, main_program, startup_program)
return outs[0]
def resize_upsample_bilinear():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]]], dtype=np.float32)
test_case = [{'name': 'bilinear_upsample_false_1', 'align_corners': False, 'align_mode': 1},
{'name': 'bilinear_upsample_false_0', 'align_corners': False, 'align_mode': 0},
{'name': 'bilinear_upsample_true_0', 'align_corners': True, 'align_mode': 0}]
for test in test_case:
pdpd_result = pdpd_interpolate(data, [64, 64], None, mode='bilinear', align_corners=test['align_corners'],
align_mode=test['align_mode'], data_format='NCHW', name=test['name'])
def resize_downsample_bilinear():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]]], dtype=np.float32)
data_28 = data.reshape([1, 1, 2, 8])
test_case = [{'name': 'bilinear_downsample_false_1', 'align_corners': False, 'align_mode': 1},
{'name': 'bilinear_downsample_false_0', 'align_corners': False, 'align_mode': 0},
{'name': 'bilinear_downsample_true_0', 'align_corners': True, 'align_mode': 0}]
for test in test_case:
pdpd_result = pdpd_interpolate(data_28, [2, 4], None, mode='bilinear', align_corners=test['align_corners'],
align_mode=test['align_mode'], data_format='NCHW', name=test['name'])
def resize_upsample_nearest():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]]], dtype=np.float32)
test_case = [
{'name': 'nearest_upsample_false_0', 'size': [64, 64], 'align_corners': False, 'align_mode': 0},
{'name': 'nearest_upsample_false_1', 'size': [16, 64], 'align_corners': False, 'align_mode': 0}
]
for test in test_case:
pdpd_result = pdpd_interpolate(data, test['size'], None, mode='nearest', align_corners=test['align_corners'],
align_mode=test['align_mode'], data_format='NCHW', name=test['name'])
def resize_downsample_nearest():
data = np.arange(0, 4096).astype(np.float32)
data_64 = data.reshape([1, 1, 64, 64])
test_case = [
{'name': 'nearest_downsample_false_0', 'size': [8, 8], 'align_corners': False, 'align_mode': 1},
{'name': 'nearest_downsample_false_1', 'size': [4, 8], 'align_corners': False, 'align_mode': 1}
]
for test in test_case:
pdpd_result = pdpd_interpolate(data_64, test['size'], None, mode='nearest', align_corners=test['align_corners'],
align_mode=test['align_mode'], data_format='NCHW', name=test['name'])
def nearest_upsample_tensor_size():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]]], dtype=np.float32)
sizes = np.array([8, 8], dtype=np.int32)
pdpd.enable_static()
test_case = [{'name': 'nearest_upsample_tensor_size', 'align_corners': False, 'align_mode': 0}]
for test in test_case:
main_program = pdpd.static.Program()
startup_program = pdpd.static.Program()
with pdpd.static.program_guard(main_program, startup_program):
node_x = pdpd.static.data(name='x', shape=data.shape, dtype='float32')
node_sizes = pdpd.static.data(name='sizes', shape=sizes.shape, dtype='int32')
interp = interpolate(node_x, size=node_sizes, scale_factor=None,
mode='nearest', align_corners=test['align_corners'], align_mode=test['align_mode'],
data_format='NCHW', name=test['name'])
out = pdpd.static.nn.batch_norm(interp, use_global_stats=True, epsilon=0)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
exe.run(startup_program)
outs = exe.run(
feed={'x': data, 'sizes': sizes},
fetch_list=out,
program=main_program)
saveModel(test['name'], exe, feedkeys=['x', 'sizes'], fetchlist=out, inputs=[data, sizes], outputs=[outs[0]], target_dir=sys.argv[1])
def bilinear_upsample_tensor_size():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]]], dtype=np.float32)
sizes = np.array([8, 8], dtype="int32")
test_case = [{'name': 'bilinear_upsample_tensor_size', 'align_corners': False, 'align_mode': 1}]
for test in test_case:
main_program = pdpd.static.Program()
startup_program = pdpd.static.Program()
with pdpd.static.program_guard(main_program, startup_program):
node_x = pdpd.static.data(name='x', shape=data.shape, dtype='float32')
node_sizes = pdpd.static.data(name='sizes', shape=sizes.shape, dtype='int32')
interp = interpolate(node_x, size=node_sizes, scale_factor=None,
mode='bilinear', align_corners=test['align_corners'], align_mode=test['align_mode'],
data_format='NCHW', name=test['name'])
out = pdpd.static.nn.batch_norm(interp, use_global_stats=True, epsilon=0)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
exe.run(startup_program)
outs = exe.run(
feed={'x': data, 'sizes': sizes},
fetch_list=out,
program=main_program)
saveModel(test['name'], exe, feedkeys=['x', 'sizes'], fetchlist=out, inputs=[data, sizes], outputs=[outs[0]], target_dir=sys.argv[1])
def bilinear_upsample_scales():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]]], dtype=np.float32)
test_case = [{'name': 'bilinear_upsample_scales', 'align_corners': False, 'align_mode': 1, "scales": 2},
{'name': 'bilinear_upsample_scales2', 'align_corners': False, 'align_mode': 1, "scales": [2, 2]}]
for test in test_case:
pdpd_result = pdpd_interpolate(data, None, 2, mode='bilinear', align_corners=test['align_corners'],
align_mode=test['align_mode'], data_format='NCHW', name=test['name'])
if __name__ == "__main__":
resize_downsample_bilinear()
resize_upsample_bilinear()
resize_downsample_nearest()
resize_upsample_nearest()
nearest_upsample_tensor_size()
bilinear_upsample_tensor_size()
bilinear_upsample_scales()

View File

@ -0,0 +1,40 @@
#
# leaky_relu paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def leaky_relu(name: str, x, alpha: float = 0.02, data_type='float32'):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype = data_type)
out = pdpd.fluid.layers.leaky_relu(node_x, alpha=alpha, name='leaky_relu')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data_type = 'float32'
data = np.array([-1, 2, 3]).astype(data_type)
leaky_relu("leaky_relu", data, 0.03)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,39 @@
#
# log paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def log(name: str, x, data_type='float32'):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.log(node_x, name='log')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data_type = 'float32'
x = np.array([0, 1, 2, -10]).astype(data_type)
log("log", x)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,44 @@
#
# pool2d paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def equal_logical_not(name : str, x, y):
import paddle as pdpd
pdpd.enable_static()
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
node_y = pdpd.static.data(name='y', shape=y.shape, dtype='float32')
out = pdpd.equal(node_x, node_y)
out = pdpd.logical_not(out)
out = pdpd.cast(out, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out],
inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
import paddle as pdpd
data_x = np.array([[[[-1, 0, 1]], [[2, 3, 4]]]]).astype(np.float32)
data_y = np.array([[[[2, 0, 3]], [[3, 1, 4]]]]).astype(np.float32)
equal_logical_not("logical_not", data_x, data_y)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,75 @@
import numpy as np
from save_model import saveModel
import sys
def pdpd_mul(name, x1, x2):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x1 = pdpd.static.data(name='x1', shape=x1.shape, dtype=x1.dtype)
node_x2 = pdpd.static.data(name='x2', shape=x2.shape, dtype=x2.dtype)
bmm_node = pdpd.fluid.layers.mul(node_x1, node_x2)
result = pdpd.static.nn.batch_norm(bmm_node, use_global_stats=True)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x1': x1, 'x2': x2},
fetch_list=[result])
saveModel(name, exe, feedkeys=['x1', 'x2'], fetchlist=[result], inputs=[x1, x2], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def pdpd_matmul(name, x1, x2, x_transpose=False, y_transpose=False):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x1 = pdpd.static.data(name='x1', shape=x1.shape, dtype=x1.dtype)
node_x2 = pdpd.static.data(name='x2', shape=x2.shape, dtype=x2.dtype)
mul_node = pdpd.fluid.layers.matmul(node_x1, node_x2, x_transpose, y_transpose)
result = pdpd.static.nn.batch_norm(mul_node, use_global_stats=True)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x1': x1, 'x2': x2},
fetch_list=[result])
saveModel(name, exe, feedkeys=['x1', 'x2'], fetchlist=[result], inputs=[x1, x2], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
if __name__ == "__main__":
input_2x5 = np.array([[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10]]).astype(np.float32)
input_5x3 = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12],
[13, 14, 15]]).astype(np.float32)
input_5x2 = np.array([[1, 2],
[4, 5],
[7, 8],
[10, 11],
[13, 14]]).astype(np.float32)
input_2x3 = np.array([[1, 2, 3],
[4, 5, 6]]).astype(np.float32)
pdpd_result = pdpd_mul("mul_fp32", input_2x5, input_5x3)
pdpd_matmul("matmul_xt", input_2x5, input_2x3, x_transpose=True, y_transpose=False)
pdpd_matmul("matmul_yt", input_2x3, input_5x3, x_transpose=False, y_transpose=True)
pdpd_matmul("matmul_xt_yt", input_2x5, input_5x2, x_transpose=True, y_transpose=True)

View File

@ -0,0 +1,70 @@
#
# pad3d paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def pad3d(name : str, x, in_dtype, pad, data_format, mode, value = 0):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name = 'x', shape = x.shape, dtype = in_dtype)
if mode == 'constant':
pad_constant = pdpd.nn.Pad3D(padding=pad, mode=mode, value=value, data_format=data_format)
out = pad_constant(node_x)
else:
pad_other_mode = pdpd.nn.Pad3D(padding=pad, mode=mode, data_format=data_format)
out = pad_other_mode(node_x)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
in_dtype = 'float32'
input_shape = (1, 2, 3, 4, 5)
pad = [1, 2, 1, 1, 3, 4]
mode = 'constant'
data_format = 'NCDHW'
value = 100
input_data = np.random.rand(*input_shape).astype(np.float32)
pad3d("pad3d_test1", input_data, in_dtype, pad, data_format, mode, value)
input_shape = (2, 3, 4, 5, 6)
pad = [1, 2, 1, 1, 1, 2]
mode = "reflect"
data_format = 'NDHWC'
input_data = np.random.rand(*input_shape).astype(np.float32)
pad3d("pad3d_test2", input_data, in_dtype, pad, data_format, mode)
input_shape = (2, 3, 4, 5, 6)
pad = [1, 2, 1, 1, 1, 2]
mode = "replicate"
data_format = 'NDHWC'
input_data = np.random.rand(*input_shape).astype(np.float32)
pad3d("pad3d_test3", input_data, in_dtype, pad, data_format, mode)
# padding of type int feature only supported by PaddlePaddle 'develop' version(>=2.1.0)
# input_shape = (1, 2, 3, 4, 5)
# pad_int = 1
# mode = 'constant'
# data_format= 'NCDHW'
# value = 100
# input_data = np.random.rand(*input_shape).astype(np.float32)
# pad3d("pad3d_test4", input_data, in_dtype, pad_int, data_format, mode, value)
if __name__ == "__main__":
main()

View File

@ -35,7 +35,6 @@ def pdpd_rnn_lstm(input_size, hidden_size, layers, direction):
fetchlist=[y, h, c, relu_1, relu_2, relu_3],
inputs=[np.ones([4, 3, input_size]).astype(np.float32)],
outputs=[outs[0], outs[1], outs[2]], target_dir=sys.argv[1])
print(outs[0])
return outs[0]

View File

@ -0,0 +1,260 @@
#
# pool2d paddle model generator
#
import numpy as np
import sys
from save_model import saveModel
data_type = 'float32'
def pool2d(name : str, x, attrs : dict):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.pool2d(node_x,
pool_size=attrs['pool_size'],
pool_type=attrs['pool_type'],
pool_stride=attrs['pool_stride'],
pool_padding=attrs['pool_padding'],
global_pooling=attrs['global_pooling'],
ceil_mode=attrs['ceil_mode'],
exclusive=attrs['exclusive'],
data_format=attrs['data_format'])
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def adaptive_pool2d(name : str, x, attrs : dict):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.adaptive_pool2d(
input=node_x,
pool_size=attrs['pool_size'],
pool_type=attrs['pool_type'],
require_index=attrs['require_index'])
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
N, C, H, W = 2, 3, 4, 4
data = np.arange(N*C*H*W).astype(data_type)
data_NCHW = data.reshape(N, C, H, W)
data_NHWC = data.reshape(N, H, W, C)
#print(data_NCHW, data_NCHW.shape)
pooling_types = ['max', 'avg']
# pool2d
for i, pooling_type in enumerate(pooling_types):
# example 1:
# ceil_mode = False
pdpd_attrs = {
# input=data_NCHW, # shape: [2, 3, 8, 8]
'pool_size' : [3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding' : [2,1], # it is same as pool_padding = [2,2,1,1]
'global_pooling' : False,
'ceil_mode' : False,
'exclusive' : True,
'data_format' : "NCHW"
}
# shape of out_1: [2, 3, 4, 3]
pool2d(pooling_type+'Pool_test1', data_NCHW, pdpd_attrs)
# Cecilia: there is a bug of PaddlePaddle in this case.
# example 2:
# ceil_mode = True (different from example 1)
pdpd_attrs = {
#input=data_NCHW,
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[[0,0], [0,0], [2,2], [1,1]], # it is same as pool_padding = [2,2,1,1]
'global_pooling':False,
'ceil_mode':True,
'exclusive':True,
'data_format':"NCHW"
}
# shape of out_2: [2, 3, 4, 4] which is different from out_1
pool2d(pooling_type+'Pool_test2', data_NCHW, pdpd_attrs)
# example 3:
# pool_padding = "SAME" (different from example 1)
pdpd_attrs = {
#input=data_NCHW,
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':"SAME",
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
# shape of out_3: [2, 3, 3, 3] which is different from out_1
pool2d(pooling_type+'Pool_test3', data_NCHW, pdpd_attrs)
# example 4:
# pool_padding = "VALID" (different from example 1)
pdpd_attrs = {
#input=data_NCHW,
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':"VALID",
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
# shape of out_4: [2, 3, 2, 2] which is different from out_1
pool2d(pooling_type+'Pool_test4', data_NCHW, pdpd_attrs)
# example 5:
# global_pooling = True (different from example 1)
# It will be set pool_size = [8,8] and pool_padding = [0,0] actually.
pdpd_attrs = {
#input=data_NCHW,
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[2,1],
'global_pooling':True,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
# shape of out_5: [2, 3, 1, 1] which is different from out_1
pool2d(pooling_type+'Pool_test5', data_NCHW, pdpd_attrs)
# example 6:
# data_format = "NHWC" (different from example 1)
pdpd_attrs = {
#input=data_NHWC, # shape: [2, 8, 8, 3]
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[2,1],
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NHWC"
}
# shape of out_6: [2, 4, 3, 3] which is different from out_1
pool2d(pooling_type+'Pool_test6', data_NHWC, pdpd_attrs)
# example 7:
# pool_size is [9, 9]
pdpd_attrs = {
#input=data_NCHW,
'pool_size':[9,9],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[[0,0], [0,0], [2,2], [1,1]], # it is same as pool_padding = [2,2,1,1]
'global_pooling':False,
'ceil_mode':True,
'exclusive':True,
'data_format':"NCHW"
}
pool2d(pooling_type+'Pool_test7', data_NCHW, pdpd_attrs)
# example 8:
# pool_padding size is 1
pdpd_attrs = {
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':2,
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
pool2d(pooling_type+'Pool_test8', data_NCHW, pdpd_attrs)
#input data for test9 and test10
N_data1, C_data1, H_data1, W_data1 = 2, 3, 8, 8
data1 = np.arange(N_data1*C_data1*H_data1*W_data1).astype(data_type)
data1_NCHW = data1.reshape(N_data1, C_data1, H_data1, W_data1)
# example 9:
# pool_padding size is 4: [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]
pdpd_attrs = {
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[2, 1, 2, 1],
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
pool2d(pooling_type+'Pool_test9', data1_NCHW, pdpd_attrs)
# example 10:
# input=data_NCHW and pool_padding is [[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]
pdpd_attrs = {
'pool_size':[3,3],
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[[0,0], [0,0], [2, 1], [2, 1]],
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
pool2d(pooling_type+'Pool_test10', data1_NCHW, pdpd_attrs)
# example 11:
# input=data_NCHW and poolsize is the multiply by width & height. pool_padding is [[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]
pdpd_attrs = {
'pool_size': 9,
'pool_type' : pooling_type,
'pool_stride' : [3,3],
'pool_padding':[[0,0], [0,0], [2, 1], [2, 1]],
'global_pooling':False,
'ceil_mode':False,
'exclusive':True,
'data_format':"NCHW"
}
pool2d(pooling_type+'Pool_test11', data1_NCHW, pdpd_attrs)
# adaptive_pool2d
for i, pooling_type in enumerate(pooling_types):
pdpd_attrs = {
'pool_size': [3,3],
'pool_type': pooling_type,
'require_index': False
}
adaptive_pool2d(pooling_type+'AdaptivePool2D_test1', data_NCHW, pdpd_attrs)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,95 @@
#
# pow paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def pdpd_pow(name : str, x, y, data_type):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.pow(node_x, y, name='pow')
#FuzzyTest supports int32 & float32
if data_type == "int64":
out = pdpd.cast(out, "float32")
out = pdpd.cast(out, "float32")
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def pdpd_pow_tensor(name : str, x, y, data_type):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
node_y = pdpd.static.data(name='y', shape=y.shape, dtype=data_type)
out = pdpd.fluid.layers.pow(node_x, node_y, name='pow')
out = pdpd.cast(out, "float32")
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'y': y},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out],
inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
test_cases = [
{
'name': "float32",
'x': np.array([0, 1, 2, -10]).astype("float32"),
'y': np.array([1.5]).astype("float32"),
'dtype': "float32",
},
{
'name': "int32",
'x': np.array([0, 1, 2, -10]).astype("int32"),
'y': np.array([2.0]).astype("float32"),
'dtype': "int32"
},
{
'name': "int64",
'x': np.array([0, 1, 2]).astype("int64"),
'y': np.array([30.0]).astype("float32"),
'dtype': "int64"
},
{
'name': "int64_out_of_range",
'x': np.array([0, 1, 2]).astype("int64"),
'y': np.array([40]).astype("float32"),
'dtype': "int64"
}
]
for test in test_cases:
pdpd_pow("pow_" + test['name'], test['x'], test['y'], test['dtype'])
x = np.array([0, 1, 2, -10]).astype("float32")
y = np.array([2.0]).astype("float32")
pdpd_pow_tensor("pow_y_tensor", x, y, 'float32')
if __name__ == "__main__":
main()

View File

@ -0,0 +1,45 @@
#
# range paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def pdpd_range(name : str, x, start, end, step, out_type):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
# Range op only support fill_constant input, since dynamic op is not supported in ov
out = pdpd.fluid.layers.range(start, end, step, out_type)
out = pdpd.cast(out, np.float32)
out = pdpd.add(node_x, out)
#out = pdpd.cast(out, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
start = 1.5
end = 10.5
step = 2
data = np.random.random([1, 5]).astype("float32")
out_type = ["float32", "int32", "int64"]
for i, dtype in enumerate(out_type):
pdpd_range("range"+str(i), data, start, end, step, dtype)
if __name__ == "__main__":
main()

View File

@ -35,4 +35,4 @@ def main():
if __name__ == "__main__":
main()
main()

View File

@ -0,0 +1,40 @@
#
# relu6 paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def relu6(name: str, x, threshold: float = 6.0, data_type='float32'):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.relu6(node_x, threshold=threshold, name='relu6')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data_type = 'float32'
data = np.array([-1, 1, 5]).astype(data_type)
relu6("relu6", data, 4)
relu6("relu6_1", data)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,78 @@
#
# reshape paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
data_type = 'float32'
def reshape(name : str, x, out_shape):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.reshape(x=node_x, shape=out_shape)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def reshape_tensor(name : str, x, out_shape, use_tensor_in_list):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
if use_tensor_in_list:
out_shape[0] = pdpd.assign(np.array((out_shape[0],)).astype('int32'))
out = pdpd.fluid.layers.reshape(x=node_x, shape=out_shape)
else:
out_shape = np.array(out_shape).astype('int32')
node_shape = pdpd.assign(out_shape)
out = pdpd.fluid.layers.reshape(x=node_x, shape=node_shape)
out = pdpd.pow(out, 1)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data = np.array([[[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
]]], dtype=np.float32)
out_shape = [1, 1, 2, 8]
reshape("reshape", data, out_shape)
reshape_tensor("reshape_tensor", data, out_shape, False)
reshape_tensor("reshape_tensor_list", data, out_shape, True)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,66 @@
import numpy as np
from save_model import saveModel
import sys
def pdpd_rnn_lstm(input_size, hidden_size, layers, direction):
import paddle as pdpd
pdpd.enable_static()
main_program = pdpd.static.Program()
startup_program = pdpd.static.Program()
num_of_directions = 1 if direction == 'forward' else 2
with pdpd.static.program_guard(main_program, startup_program):
rnn = pdpd.nn.LSTM(input_size, hidden_size, layers, direction)
data = pdpd.static.data(name='x', shape=[4, 3, input_size], dtype='float32')
prev_h = pdpd.ones(shape=[layers * num_of_directions, 4, hidden_size], dtype=np.float32)
prev_c = pdpd.ones(shape=[layers * num_of_directions, 4, hidden_size], dtype=np.float32)
y, (h, c) = rnn(data, (prev_h, prev_c))
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
exe.run(startup_program)
outs = exe.run(
feed={'x': np.ones([4, 3, input_size]).astype(np.float32)},
fetch_list=[y, h, c],
program=main_program)
saveModel("rnn_lstm_layer_" + str(layers) + '_' + str(direction), exe, feedkeys=['x'],
fetchlist=[y, h, c], inputs=[np.ones([4, 3, input_size]).astype(np.float32)], outputs=[outs[0], outs[1], outs[2]], target_dir=sys.argv[1])
return outs[0]
if __name__ == "__main__":
testCases = [
{
'input_size': 2,
'hidden_size': 2,
'layers': 1,
'direction': 'forward',
},
{
'input_size': 2,
'hidden_size': 2,
'layers': 1,
'direction': 'bidirectional',
},
{
'input_size': 2,
'hidden_size': 2,
'layers': 2,
'direction': 'forward',
},
{
'input_size': 2,
'hidden_size': 2,
'layers': 2,
'direction': 'bidirectional',
}
]
for test in testCases:
pdpd_rnn_lstm(test['input_size'], test['hidden_size'], test['layers'], test['direction'])

View File

@ -0,0 +1,93 @@
#
# pool2d paddle model generator
#
import numpy as np
import sys
from save_model import saveModel
def pdpd_scale(name : str, x, scale, bias, attrs : dict, data_type):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.scale(x=node_x, scale=scale, bias=bias,
bias_after_scale=attrs['bias_after_scale'])
#FuzzyTest only support FP32 now, so cast result to fp32
out = pdpd.cast(out, "float32")
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def pdpd_scale_tensor(name : str, x, scale, bias, attrs : dict, data_type):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
node_scale = pdpd.static.data(name='scale', shape=[1], dtype='float32')
out = pdpd.scale(x=node_x, scale=node_scale, bias=bias,
bias_after_scale=attrs['bias_after_scale'])
#FuzzyTest only support FP32 now, so cast result to fp32
out = pdpd.cast(out, "float32")
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'scale': scale},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x', 'scale'], fetchlist=[out], inputs=[x, np.array([scale]).astype('float32')], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
scale = 2.0
bias = 1.0
data = np.random.random([2, 3]).astype("float32")
test_cases = [
"float32",
"int32",
"int64"
]
pdpd_attrs = {
'bias_after_scale': True,
}
pdpd_scale_tensor("scale_tensor_bias_after", data, scale, bias, pdpd_attrs, 'float32')
pdpd_attrs = {
'bias_after_scale': False,
}
pdpd_scale_tensor("scale_tensor_bias_before", data, scale, bias, pdpd_attrs, 'float32')
for test in test_cases:
data = np.random.random([2, 3]).astype(test)
pdpd_attrs = {
'bias_after_scale': True,
}
pdpd_scale("scale_bias_after_" + test, data, scale, bias, pdpd_attrs, test)
pdpd_attrs = {
'bias_after_scale': False,
}
pdpd_scale("scale_bias_before_" + test, data, scale, bias, pdpd_attrs, test)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,38 @@
#
# pool2d paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def pdpd_shape(name : str, x):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
out = pdpd.shape(node_x)
out = pdpd.cast(out, np.float32)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data = np.random.random(size=(2, 3)).astype('float32')
pdpd_shape("shape", data)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,39 @@
#
# sigmoid paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
def sigmoid(name: str, x, data_type):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type)
out = pdpd.fluid.layers.sigmoid(node_x, name='sigmoid')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out],
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data_type = 'float32'
data = np.array([0, 1, -1]).astype(data_type)
sigmoid("sigmoid", data, data_type)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,39 @@
#
# slice paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
data_type = 'float32'
def slice(name : str, x, axes : list, start : list, end : list):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype = data_type)
out = pdpd.fluid.layers.slice(node_x, axes = axes, starts = start, ends = end)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
x = np.linspace(1, 60, num = 60, dtype=np.int32).reshape(4, 3, 5).astype(data_type)
slice("slice", x, axes=[1, 2], start=(0, 1), end=(-1, 3))
x = np.linspace(1, 60, num = 60, dtype=np.int32).reshape(2, 30).astype(data_type)
slice("slice_1d", x, axes=[0], start=[0], end=[1])
if __name__ == "__main__":
main()

View File

@ -0,0 +1,45 @@
#
# softmax paddle model generator
#
import numpy as np
import sys
from save_model import saveModel
def softmax(name: str, x, axis):
import paddle as pdpd
pdpd.enable_static()
node_x = pdpd.static.data(name='x', shape=x.shape, dtype='float32')
out = pdpd.nn.functional.softmax(x=node_x, axis=axis)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data = np.array(
[[[2.0, 3.0, 4.0, 5.0],
[3.0, 4.0, 5.0, 6.0],
[7.0, 8.0, 8.0, 9.0]],
[[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0],
[6.0, 7.0, 8.0, 9.0]]]
).astype(np.float32)
softmax("softmax", data, axis=1)
softmax("softmax_minus", data, axis=-1)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,115 @@
#
# split paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def split(name : str, x, attrs : dict):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=x.dtype)
out = pdpd.fluid.layers.split(node_x, num_or_sections=attrs['num_or_sections'], dim=attrs['axis'])
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
print("outputs: ", type(outs),len(outs))
print("out: ", type(out), len(out))
saveModel(name, exe, feedkeys=['x'], fetchlist=out, inputs=[x], outputs=outs, target_dir=sys.argv[1])
return outs[0]
def split_dim_tensor(name : str, x, attrs : dict, dim):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=x.dtype)
dim_node = pdpd.assign(dim)
out = pdpd.fluid.layers.split(node_x, num_or_sections=attrs['num_or_sections'], dim=dim_node)
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
print("outputs: ", type(outs),len(outs))
print("out: ", type(out), len(out))
saveModel(name, exe, feedkeys=['x'], fetchlist=out, inputs=[x], outputs=outs, target_dir=sys.argv[1])
return outs[0]
def split_test_list_tensor(name : str, x, attrs : dict):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=x.dtype)
section = attrs['num_or_sections']
section[0] = pdpd.assign(np.array((section[0],)).astype('int32'))
out = pdpd.fluid.layers.split(node_x, num_or_sections=section, dim=attrs['axis'])
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
print("outputs: ", type(outs),len(outs))
print("out: ", type(out), len(out))
saveModel(name, exe, feedkeys=['x'], fetchlist=out, inputs=[x], outputs=outs, target_dir=sys.argv[1])
return outs[0]
def main():
# split
data_types = ['float32'] #TODOD: ['bool', 'float16', 'float32', 'float64', 'int32', 'int64']
num_or_sections = [3, [2, 3, 4], [2, 3, -1]]
axes = [1, -2]
idx = 1
for t in data_types:
for s in num_or_sections:
for i in axes:
pdpd_attrs = {
'num_or_sections': s,
'axis': i
}
data_NCHW = np.random.rand(3,9,5).astype(t)
split("split_test{}".format(idx), data_NCHW, pdpd_attrs)
idx+=1
split("split_test_list", data_NCHW, {
'num_or_sections': [4, 5],
'axis': 1})
split_dim_tensor("split_test_dim_int32", data_NCHW, {
'num_or_sections': 3}, np.array([1,]).astype('int32'))
split_dim_tensor("split_test_dim_int64", data_NCHW, {
'num_or_sections': 3}, np.array([1,]).astype('int64'))
split_test_list_tensor("split_test_list_tensor", data_NCHW, {
'num_or_sections': [4, 5],
'axis': 1})
if __name__ == "__main__":
main()

View File

@ -0,0 +1,38 @@
#
# squeeze paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
data_type = 'float32'
def squeeze(name : str, x, axes : list):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype = data_type)
out = pdpd.fluid.layers.squeeze(node_x, axes=axes, name='squeeze')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data = np.random.rand(1, 3, 1, 4).astype(data_type)
squeeze("squeeze", data, [0, -2])
squeeze("squeeze_null_axes", data, [])
if __name__ == "__main__":
main()

View File

@ -0,0 +1,37 @@
#
# unsqueeze paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys
data_type = 'float32'
def unsqueeze(name : str, x, axes : list):
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype = data_type)
out = pdpd.fluid.layers.unsqueeze(node_x, axes = axes, name = 'unsqueeze')
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x},
fetch_list=[out])
saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1])
return outs[0]
def main():
data = np.random.rand(5, 10).astype(data_type)
unsqueeze("unsqueeze", data, [1])
if __name__ == "__main__":
main()

View File

@ -0,0 +1,114 @@
#
# pool2d paddle model generator
#
import numpy as np
from save_model import saveModel
import sys
def yolo_box(name : str, x, img_size, attrs : dict):
import paddle as pdpd
pdpd.enable_static()
with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
node_x = pdpd.static.data(name='x', shape=x.shape, dtype=x.dtype)
node_img_size = pdpd.static.data(name='img_size', shape=img_size.shape, dtype=img_size.dtype)
boxes, scores = pdpd.vision.ops.yolo_box(node_x,
node_img_size,
anchors=attrs['anchors'],
class_num=attrs['class_num'],
conf_thresh=attrs['conf_thresh'],
downsample_ratio=attrs['downsample_ratio'],
clip_bbox=attrs['clip_bbox'],
name=None,
scale_x_y=attrs['scale_x_y'])
cpu = pdpd.static.cpu_places(1)
exe = pdpd.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(pdpd.static.default_startup_program())
outs = exe.run(
feed={'x': x, 'img_size': img_size},
fetch_list=[boxes, scores])
# Save inputs in order of ngraph function, to facilite Fuzzy test,
# which accepts inputs and outputs in this order as well.
saveModel(name, exe, feedkeys=['x', 'img_size'], fetchlist=[boxes, scores],
inputs=[x, img_size], outputs=outs, target_dir=sys.argv[1])
return outs
def TEST1():
# yolo_box
pdpd_attrs = {
'name': "yolo_box_default",
'anchors': [10, 13, 16, 30, 33, 23],
'class_num': 2,
'conf_thresh': 0.5,
'downsample_ratio': 32,
'clip_bbox': False,
'scale_x_y': 1.0
}
pdpd_attrs_clip_box = {
'name': "yolo_box_clip_box",
'anchors': [10, 13, 16, 30, 33, 23],
'class_num': 2,
'conf_thresh': 0.5,
'downsample_ratio': 32,
'clip_bbox': True,
'scale_x_y': 1.0
}
pdpd_attrs_scale_xy = {
'name': "yolo_box_scale_xy",
'anchors': [10, 13, 16, 30, 33, 23],
'class_num': 2,
'conf_thresh': 0.5,
'downsample_ratio': 32,
'clip_bbox': True,
'scale_x_y': 1.2
}
pdpd_attrs_list = [pdpd_attrs, pdpd_attrs_clip_box, pdpd_attrs_scale_xy]
N = 32
num_anchors = int(len(pdpd_attrs['anchors'])//2)
x_shape = (N, num_anchors * (5 + pdpd_attrs['class_num']), 13, 13)
imgsize_shape = (N, 2)
data = np.random.random(x_shape).astype('float32')
data_ImSize = np.random.randint(10, 20, imgsize_shape).astype('int32')
for item in pdpd_attrs_list:
pred_pdpd = yolo_box(item['name'], data, data_ImSize, item)
def TEST2():
# yolo_box uneven spatial width and height
pdpd_attrs = {
'name': "yolo_box_uneven_wh",
'anchors': [10, 13, 16, 30, 33, 23],
'class_num': 2,
'conf_thresh': 0.5,
'downsample_ratio': 32,
'clip_bbox': False,
'scale_x_y': 1.0
}
N = 16
SPATIAL_WIDTH = 13
SPATIAL_HEIGHT = 9
num_anchors = int(len(pdpd_attrs['anchors'])//2)
x_shape = (N, num_anchors * (5 + pdpd_attrs['class_num']), SPATIAL_HEIGHT, SPATIAL_WIDTH)
imgsize_shape = (N, 2)
data = np.random.random(x_shape).astype('float32')
data_ImSize = np.random.randint(10, 20, imgsize_shape).astype('int32')
pred_pdpd = yolo_box(pdpd_attrs['name'], data, data_ImSize, pdpd_attrs)
if __name__ == "__main__":
TEST1()
TEST2()

View File

@ -29,26 +29,25 @@ def print_alike(arr):
line += end
#print(line)
return line
# print(print_array(arr, "}"))
print(print_array(arr, "}"))
def saveModel(name, exe, feedkeys:list, fetchlist:list, inputs:list, outputs:list, target_dir:str):
model_dir = os.path.join(target_dir, name)
if not os.path.exists(model_dir):
os.makedirs(model_dir)
print("\n\n------------- %s -----------\n" % (name))
# print("\n\n------------- %s -----------\n" % (name))
for i, input in enumerate(inputs):
print("INPUT %s :" % (feedkeys[i]), input.shape, input.dtype, "\n")
print_alike(input)
# print("INPUT %s :" % (feedkeys[i]), input.shape, input.dtype, "\n")
# print_alike(input)
np.save(os.path.join(model_dir, "input{}".format(i)), input)
np.save(os.path.join(model_dir, "input{}.{}.{}".format(i, feedkeys[i], input.dtype)), input)
print("\n")
# print("\n")
for i, output in enumerate(outputs):
print("OUTPUT %s :" % (fetchlist[i]),output.shape, output.dtype, "\n")
print_alike(output)
# print("OUTPUT %s :" % (fetchlist[i]),output.shape, output.dtype, "\n")
# print_alike(output)
np.save(os.path.join(model_dir, "output{}".format(i)), output)
# composited model + scattered model
@ -76,5 +75,4 @@ if __name__ == "__main__":
[
[1, 2, 3],
[4, 5, 6]
]]]).astype(np.float32)
print_alike(x)
]]]).astype(np.float32)