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