def test_nn_functional_interpolate_nearest_date_format(): """ api: paddle.nn.functional.interpolate op version: 11 """ op = Net(size=[4, 12], data_format='NHWC') op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_functional_interpolate', [11]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [2, 2, 2, 10]).astype('float32'))) obj.run()
def test_nn_functional_interpolate_bicubic_align_corners(): """ api: paddle.nn.functional.interpolate op version: 11 """ op = Net(mode='bicubic', scale_factor=1.5, align_corners=True) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_functional_interpolate', [11]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [1, 2, 2, 5]).astype('float32'))) obj.run()
def test_AdaptiveAvgPool1D_base(): """ api: paddle.nn.AdaptiveAvgPool1D op version: 9, 10, 11, 12 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_AdaptiveAvgPool1D', [9, 10, 11, 12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10]).astype('float32'))) obj.run()
def test_LayerNorm_11(): """ api: paddle.nn.LayerNorm op version: 11 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_LayerNorm', [11]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def test_MaxPool2D_base_Padding_0(): """ api: paddle.MaxPool2D op version: 9, 10, 11, 12 """ op = Net(kernel_size=5, padding=[[0, 0], [0, 0], [1, 2], [3, 4]]) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_MaxPool2D', [9, 10, 11, 12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def test_transpose_10(): """ api: paddle.transpose op version: 10 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'transpose', [10]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [1, 3, 10]).astype('float32'))) obj.run()
def test_Pad1D_replicate(): """ api: paddle.nn.Pad1D op version: 12 """ op = Net(mode='replicate') op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_Pad1D', [12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10]).astype('float32'))) obj.run()
def test_Conv2D_padding_2_9(): """ api: paddle.nn.Conv2D op version: 9 """ op = Net(padding=[[0, 0], [0, 0], [1, 2], [2, 3]]) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'Conv2D', [9]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def test_InstanceNorm_base(): """ api: paddle.InstanceNorm op version: 9, 10, 11, 12 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_InstanceNorm', [9, 10, 11, 12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [2, 2, 2, 2, 3]).astype('float32'))) obj.run()
def test_avg_pool2d_12(): """ api: paddle.nn.functional.avg_pool2d op version: 12 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'avg_pool2d', [12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def test_nn_functional_selu_scale(): """ api: paddle.nn.functional.selu op version: 12 """ op = Net(scale=2) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn.functional.selu', [12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 3, 3]).astype('float32'))) obj.run()
def test_squeeze_9_None(): """ api: paddle.squeeze op version: 12 """ op = Net(axis=None) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'squeeze', [9, 10, 11, 12, 13]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [1, 3, 10, 1]).astype('float32'))) obj.run()
def test_Conv3DTranspose_padding_1_9_10_11_12(): """ api: paddle.Conv3DTranspose op version: 9,10,11,12 """ op = Net(padding=[1, 2, 3, 4, 5, 6]) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_Conv3DTranspose', [9, 10, 11, 12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10, 10]).astype('float32'))) obj.run()
def test_Conv3DTranspose_output_padding_2_9_10_11_12(): """ api: paddle.Conv3DTranspose op version: 9,10,11,12 """ op = Net(in_channels=16, out_channels=16, stride=3, output_padding=2) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_Conv3DTranspose', [9, 10, 11, 12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 16, 10, 10, 10]).astype('float32'))) obj.run()
def test_Hardsigmoid_10(): """ api: paddle.nn.Hardsigmoid op version: 10 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_Hardsigmoid', [10]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def test_GroupNorm_12(): """ api: paddle.nn.GroupNorm op version: 12 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_GroupNorm', [12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [5, 10, 8, 8]).astype('float32'))) obj.run()
def test_BatchNorm2D_9(): """ api: paddle.nn.BatchNorm2D op version: 9 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_BatchNorm2D', [9]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def test_Conv2D_dilation_2_9(): """ api: paddle.nn.Conv2D op version: 9 """ op = Net(in_channels=16, out_channels=16, dilation=3) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'Conv2D', [9]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 16, 10, 10]).astype('float32'))) obj.run()
def test_Conv1DTranspose_12_Padding_tuple1(): """ api: paddle.nn.Conv1DTranspose op version: 12 """ op = Net(padding=(1, 2)) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_Conv1DTranspose', [9, 10, 11, 12, 13]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10]).astype('float32'))) obj.run()
def test_initializer_Uniform_base(): """ api: paddle.initializer.Uniform op version: 9 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_initializer_Uniform', [9, 10, 11, 12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 2]).astype('float32'))) obj.run()
def test_Conv3D_10(): """ api: paddle.Conv3D op version: 10 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'Conv2D_Dropout', [10]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 5, 10, 10]).astype('float32'))) obj.run()
def test_square_9(): """ api: paddle.square op version: 9 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'square', [9]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 3, 3]).astype('float32'))) obj.run()
def test_argmin_axis_keepdim(): """ api: paddle.argmin op version: 12 """ op = Net(axis=1, keepdim=True) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'argmin', [12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 3, 10]).astype('float32'))) obj.run()
def test_neg_12(): """ api: paddle.neg op version: 12 """ op = Net() op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'neg', [12]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 3, 3]).astype('float32'))) obj.run()
def test_nn_functional_interpolate_nearest_scale_factor_tuple(): """ api: paddle.nn.functional.interpolate op version: 11 """ op = Net(scale_factor=(1, 2)) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_functional_interpolate', [11]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [2, 3, 6, 10]).astype('float32'))) obj.run()
def test_argsort_descending_1(): """ api: paddle.argsort op version: 12 """ op = Net(descending=True) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'argsort', [7]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 3, 10]).astype('float32'))) obj.run()
def test_Conv2DTranspose_9_output_padding_3(): """ api: paddle.Conv2DTranspose op version: 9 """ op = Net(output_padding=1, stride=[3, 2], padding=[[0, 0], [0, 0], [1, 2], [2, 3]]) op.eval() # net, name, ver_list, delta=1e-6, rtol=1e-5 obj = APIOnnx(op, 'nn_Conv2DTranspose', [9]) obj.set_input_data( "input_data", paddle.to_tensor( randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32'))) obj.run()
def generator_data(): input_data = randtool("int", 0, 10, input2_shape) return input_data
def run_test(self, configs): config, models = configs logging.info("Run configs: {}".format(config)) assert "op_names" in config.keys( ), "config must include op_names in dict keys" assert "test_data_shapes" in config.keys( ), "config must include test_data_shapes in dict keys" assert "test_data_types" in config.keys( ), "config must include test_data_types in dict keys" assert "opset_version" in config.keys( ), "config must include opset_version in dict keys" assert "input_spec_shape" in config.keys( ), "config must include input_spec_shape in dict keys" op_names = config["op_names"] test_data_shapes = config["test_data_shapes"] test_data_types = config["test_data_types"] opset_version = config["opset_version"] input_specs = config["input_spec_shape"] use_gpu = True if "use_gpu" in config.keys(): use_gpu = config["use_gpu"] self.num_ran_models += 1 if not isinstance(models, (tuple, list)): models = [models] if not isinstance(op_names, (tuple, list)): op_names = [op_names] if not isinstance(opset_version[0], (tuple, list)): opset_version = [opset_version] if len(opset_version) == 1 and len(models) != len(opset_version): opset_version = opset_version * len(models) assert len(models) == len( op_names), "Length of models should be equal to length of op_names" input_type_list = None if len(test_data_types) > 1: input_type_list = list(product(*test_data_types)) elif len(test_data_types) == 1: if isinstance(test_data_types[0], str): input_type_list = [test_data_types[0]] else: input_type_list = test_data_types elif len(test_data_types) == 0: input_type_list = [["float32"] * len(test_data_shapes)] delta = 1e-5 rtol = 1e-5 if "delta" in config.keys(): delta = config["delta"] if "rtol" in config.keys(): rtol = config["rtol"] for i, model in enumerate(models): model.eval() obj = APIOnnx(model, op_names[i], opset_version[i], op_names[i], input_specs, delta, rtol, use_gpu) for input_type in input_type_list: input_tensors = list() for j, shape in enumerate(test_data_shapes): # Determine whether it is a user-defined data generation function if isfunction(shape): data = shape() data = data.astype(input_type[j]) input_tensors.append(paddle.to_tensor(data)) continue if input_type[j].count('int') > 0: input_tensors.append( paddle.to_tensor( randtool("int", -20, 20, shape).astype(input_type[j]))) elif input_type[j].count('bool') > 0: input_tensors.append( paddle.to_tensor( randtool("bool", -2, 2, shape).astype(input_type[j]))) else: input_tensors.append( paddle.to_tensor( randtool("float", -2, 2, shape).astype(input_type[j]))) obj.set_input_data("input_data", tuple(input_tensors)) logging.info("Now Run >>> dtype: {}, op_name: {}".format( input_type, op_names[i])) obj.run() if len(input_type_list) == 0: obj.run() logging.info("Run Successfully!")
def generator3_data(): input_data3 = randtool("int", 1, 10, [input_shape[2]]) return input_data3