示例#1
0
 def test_transpose_permute(self,
                            minimum_ios_deployment_target='13'
                            ):  # type: () -> None
     _test_single_node(
         "Transpose", [(5, 3, 4, 6, 2)], [(2, 3, 4, 6, 5)],
         axes=[4, 1, 2, 3, 0],
         minimum_ios_deployment_target=minimum_ios_deployment_target)
示例#2
0
 def test_split_axis_0_rank_3(self,
                              minimum_ios_deployment_target='12'
                              ):  # type: () -> None
     _test_single_node(
         "Split", [(2, 1, 200)], [(1, 1, 200), (1, 1, 200)],
         axes=0,
         minimum_ios_deployment_target=minimum_ios_deployment_target)
示例#3
0
    def test_avg_pool(self):  # type: () -> None
        kernel_shape = (5, 3)
        pads = (2, 1, 2, 1)
        strides = (1, 2)

        input_shape = (1, 3, 224, 224)
        output_size = _conv_pool_output_size(input_shape, (1, 1),
                                             kernel_shape, pads, strides)
        output_shape = (1, 3, output_size[0], output_size[1])
        _test_single_node(
            "AveragePool",
            [input_shape],
            [output_shape],
            test_name='test_avg_pool_1',
            kernel_shape=kernel_shape,
            pads=pads,
            strides=strides
        )

        output_size = _conv_pool_output_size(input_shape, (1, 1),
                                             kernel_shape, [0, 0, 0, 0],
                                             strides)
        output_shape = (1, 3, output_size[0], output_size[1])
        _test_single_node(
            "AveragePool",
            [input_shape],
            [output_shape],
            test_name='test_avg_pool_2',
            kernel_shape=kernel_shape,
            strides=strides
        )
示例#4
0
    def test_conv_transpose(self):  # type: () -> None
        kernel_shape = (3, 3)
        pads = (0, 0, 0, 0)
        C_in  = 3
        C_out = 12
        H_in, W_in = 30, 30
        strides = (2, 2)

        input_shape = (1, C_in, H_in, W_in)
        weight = from_array(_random_array((C_in, C_out, kernel_shape[0], kernel_shape[1])),
                            name="weight")

        H_out = (H_in-1) * strides[0] + kernel_shape[0] - pads[0] - pads[2]
        W_out = (W_in-1) * strides[1] + kernel_shape[1] - pads[1] - pads[3]
        output_shape = (1, C_out, H_out, W_out)

        _test_single_node(
            "ConvTranspose",
            [input_shape],
            [output_shape],
            initializer=[weight],
            # Default values for other attributes: dilations=[1, 1], group=1
            strides = strides,
            kernel_shape=kernel_shape,
            pads=pads,
            output_padding=(0, 0)
        )
示例#5
0
 def test_reshape_same_rank_infer_shape(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Reshape",
         [(5, 4, 3), (3,)],
         [(5, 2, 6)],
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#6
0
    def test_bn(self):  # type: () -> None
        scale = from_array(_random_array((3,)), name="scale")
        bias = from_array(_random_array((3,)), name="bias")
        mean = from_array(_random_array((3,)), name="mean")
        var = from_array(_random_array((3,)), name="var")

        epsilon = 1e-5
        momentum = 0.001

        op_types = ["BatchNormalization", "SpatialBN"]
        for op_type in op_types:
            _test_single_node(
                "BatchNormalization",
                [(1, 3, 224, 224)],
                [(1, 3, 224, 224)],
                initializer=[scale, bias, mean, var],
                epsilon=epsilon,
                momentum=momentum
            )

            # epsilon by default
            _test_single_node(
                "BatchNormalization",
                [(1, 3, 224, 224)],
                [(1, 3, 224, 224)],
                initializer=[scale, bias, mean, var],
                # epsilon=epsilon,
                momentum=momentum
            )
示例#7
0
    def test_max_pool(self):  # type: () -> None
        kernel_shape = (5, 3)
        pads = (2, 1, 2, 1)
        strides = (1, 2)

        input_shape = (1, 3, 224, 224)

        output_size = _conv_pool_output_size(input_shape, [1, 1],
                                             kernel_shape, pads, strides)

        output_shape = (1, 3, output_size[0], output_size[1])

        _test_single_node(
            "MaxPool",
            [input_shape],
            [output_shape],
            kernel_shape=kernel_shape,
            pads=pads,
            strides=strides
        )

        output_size = _conv_pool_output_size(input_shape, [1, 1],
                                             kernel_shape, [0, 0, 0, 0],
                                             strides)
        output_shape = (1, 3, output_size[0], output_size[1])
        _test_single_node(
            "MaxPool",
            [input_shape],
            [output_shape],
            kernel_shape=kernel_shape,
            strides=strides
        )
示例#8
0
 def test_reshape_dynamic(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Reshape",
         [(5, 4, 3, 2), (3,)],
         [(2, 3, 20)],
         disable_rank5_mapping=disable_rank5_mapping
     )  
示例#9
0
 def test_transpose_default(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Transpose",
         [(5, 3, 4, 6, 2)],
         [(2, 6, 4, 3, 5)],
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#10
0
 def test_slice_axis_0_rank_2(self):  # type: () -> None
     _test_single_node("Slice", [(10, 2)], [(5, 2)],
                       onnx_coreml_input_shape_map={'input0': [3, 4]},
                       coreml_input_shape={'input0': [1, 10, 2]},
                       axes=[0],
                       starts=[5],
                       ends=[10])
示例#11
0
    def test_conv(self):  # type: () -> None
        kernel_shape = (3, 2)
        strides = (2, 3)
        pads = (4, 2, 4, 2)
        dilations = (1, 2)
        group = 1
        weight = from_array(_random_array((16, 3, 3, 2)), name="weight")

        input_shape = (1, 3, 224, 224)
        output_size = _conv_pool_output_size(input_shape, dilations,
                                             kernel_shape, pads, strides)

        output_shape = (1, int(weight.dims[0]), output_size[0], output_size[1])

        _test_single_node(
            "Conv",
            [input_shape],
            [output_shape],
            initializer=[weight],
            dilations=dilations,
            group=group,
            kernel_shape=kernel_shape,
            pads=pads,
            strides=strides
        )
示例#12
0
 def test_split_axis_0_rank_3(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Split",
         [(2, 1, 200)],
         [(1, 1, 200), (1, 1, 200)],
         axes=0,
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#13
0
 def test_concat(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Concat",
         [(1, 2, 200), (1, 2, 200)],
         [(2, 2, 200)],
         axis=0,
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#14
0
 def test_gather(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Gather",
         [(5, 4, 3), (3,)],
         [(3, 4, 3)],
         axis=0,
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#15
0
 def test_squeeze(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Squeeze",
         [(5, 1, 3, 1, 1)],
         [(5, 3)],
         axes=[1, 3, 4],
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#16
0
 def test_transpose_permute(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Transpose",
         [(5, 3, 4, 6, 2)],
         [(2, 3, 4, 6, 5)],
         axes=[4, 1, 2, 3, 0],
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#17
0
 def test_unsqueeze(self, disable_rank5_mapping=True):  # type: () -> None
     _test_single_node(
         "Unsqueeze",
         [(5, 3, 4)],
         [(1, 5, 1, 3, 4)],
         axes=[0, 1],
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#18
0
 def test_slice_axis_3_rank_4(self,
                              disable_rank5_mapping=False
                              ):  # type: () -> None
     _test_single_node("Slice", [(1, 3, 224, 224)], [(1, 3, 224, 222)],
                       axes=[3],
                       starts=[1],
                       ends=[223],
                       disable_rank5_mapping=disable_rank5_mapping)
示例#19
0
 def test_slice_axis_3_rank_4(self):  # type: () -> None
     _test_single_node(
         "Slice",
         [(1, 3, 224, 224)],
         [(1, 3, 224, 222)],
         axes=[3],
         starts=[1],
         ends=[223]
     )
示例#20
0
 def test_gemm(self):  # type: () -> None
     input_shape = (1, 2048)
     output_shape = (1, 5)
     W = from_array(_random_array((output_shape[1], input_shape[1])),
                    name="weight")
     b = from_array(_random_array((output_shape[1], )), name="bias")
     _test_single_node("Gemm", [input_shape], [output_shape],
                       initializer=[W, b],
                       decimal=3,
                       transB=1)
示例#21
0
 def test_lrn(self):  # type: () -> None
     _test_single_node(
         "LRN",
         [(1, 3, 224, 224)],
         [(1, 3, 224, 224)],
         alpha=9.99e-5,
         beta=0.75,
         bias=1.0,
         size=5
     )
示例#22
0
 def test_gemm_transB_off(self, target_ios='12'):  # type: () -> None
     input_shape = (1, 2048)
     output_shape = (1, 5)
     W = from_array(_random_array((input_shape[1], output_shape[1])),
                    name="weight")
     b = from_array(_random_array((output_shape[1], )), name="bias")
     _test_single_node("Gemm", [input_shape], [output_shape],
                       initializer=[W, b],
                       decimal=3,
                       transB=0,
                       target_ios=target_ios)
示例#23
0
 def test_gemm(self,
               minimum_ios_deployment_target='12'):  # type: () -> None
     input_shape = (1, 2048)
     output_shape = (1, 5)
     W = from_array(_random_array((output_shape[1], input_shape[1])),
                    name="weight")
     b = from_array(_random_array((output_shape[1], )), name="bias")
     _test_single_node(
         "Gemm", [input_shape], [output_shape],
         initializer=[W, b],
         decimal=3,
         transB=1,
         minimum_ios_deployment_target=minimum_ios_deployment_target)
示例#24
0
 def test_gemm_transB_off(self, disable_rank5_mapping=False):  # type: () -> None
     input_shape = (1, 2048)
     output_shape = (1, 5)
     W = from_array(
         _random_array((input_shape[1], output_shape[1])), name="weight"
     )
     b = from_array(
         _random_array((output_shape[1],)), name="bias"
     )
     _test_single_node(
         "Gemm",
         [input_shape],
         [output_shape],
         initializer=[W, b],
         decimal=3,
         transB=0,
         disable_rank5_mapping=disable_rank5_mapping
     )
示例#25
0
 def test_concat(self):
     _test_single_node("Concat", [(1, 3, 128, 256), (1, 3, 128, 256)],
                       [(6, 128, 256)])
示例#26
0
 def test_sigmoid(self):
     _test_single_node("Sigmoid", [(1, 3, 224, 224)], [(1, 3, 224, 224)])
示例#27
0
 def test_softmax(self):
     _test_single_node("Softmax", [(1, 100, 1, 1)], [(1, 100, 1, 1)])
示例#28
0
 def test_reshape(self):
     _test_single_node("Reshape", [(3, 224, 224)], [(1, 3 * 224 * 224)],
                       shape=(1, 3 * 224 * 224))
示例#29
0
 def test_transpose(self):
     _test_single_node("Transpose", [(3, 224, 224)], [(224, 3, 224)],
                       perm=(1, 0, 2))
示例#30
0
 def test_transpose_default(self):
     _test_single_node("Transpose", [(4, 5, 6)], [(6, 5, 4)])