Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
        )
Exemplo n.º 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)
        )
Exemplo n.º 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
     )
Exemplo n.º 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
            )
Exemplo n.º 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
        )
Exemplo n.º 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
     )  
Exemplo n.º 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
     )
Exemplo n.º 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])
Exemplo n.º 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
        )
Exemplo n.º 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
     )
Exemplo n.º 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
     )
Exemplo n.º 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
     )
Exemplo n.º 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
     )
Exemplo n.º 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
     )
Exemplo n.º 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
     )
Exemplo n.º 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)
Exemplo n.º 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]
     )
Exemplo n.º 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)
Exemplo n.º 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
     )
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
     )
Exemplo n.º 25
0
 def test_concat(self):
     _test_single_node("Concat", [(1, 3, 128, 256), (1, 3, 128, 256)],
                       [(6, 128, 256)])
Exemplo n.º 26
0
 def test_sigmoid(self):
     _test_single_node("Sigmoid", [(1, 3, 224, 224)], [(1, 3, 224, 224)])
Exemplo n.º 27
0
 def test_softmax(self):
     _test_single_node("Softmax", [(1, 100, 1, 1)], [(1, 100, 1, 1)])
Exemplo n.º 28
0
 def test_reshape(self):
     _test_single_node("Reshape", [(3, 224, 224)], [(1, 3 * 224 * 224)],
                       shape=(1, 3 * 224 * 224))
Exemplo n.º 29
0
 def test_transpose(self):
     _test_single_node("Transpose", [(3, 224, 224)], [(224, 3, 224)],
                       perm=(1, 0, 2))
Exemplo n.º 30
0
 def test_transpose_default(self):
     _test_single_node("Transpose", [(4, 5, 6)], [(6, 5, 4)])