(builder, node, graph, err)
convert to CoreML Convolution Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L1418
convert to CoreML Convolution Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L1418
convert to CoreML Convolution Layer : https : // github . com / apple / coremltools / blob / 655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492 / mlmodel / format / NeuralNetwork . proto#L1418
def _convert_conv(builder, node, graph, err):
    '''
    convert to CoreML Convolution Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L1418
    '''
    params_dict = dict()
    params_dict['is_deconv'] = False
    if node.op_type.endswith("Transpose"):
        params_dict['is_deconv'] = True
    #get weights for convolution
    weight_name = node.inputs[1]
    W = None
    if weight_name in node.input_tensors:
        W = node.input_tensors[weight_name]
        params_dict['w_shape'] = W.shape
    else:
        # W is provided as a input
        # Make W compatible for CoreML Conv Layer
        # W ONNX format: OC x KC x H x W
        # Expected CoreML Format: H x W x KC x OC
        W_name = node.inputs[1]
        W_shape = graph.shape_dict[W_name]
        W_rank  = len(W_shape)

        params_dict['w_shape'] = W_shape
        if W_rank == 3:
            expanded_node_name = node.name + '_' + W_name + '_expanded'
            builder.add_expand_dims(
                name=node.name+'_w_expand',
                input_name=W_name,
                output_name=expanded_node_name,
                axes=[-2]
            )
            W_name = expanded_node_name

        # Now Permute the W tensor
        W_transpose_axes=[2, 3, 1, 0]
        # If ConvTranpose then, Kernel and Output channels are shuffled
        if params_dict['is_deconv']:
            W_transpose_axes=[2, 3, 0, 1]
    
        builder.add_transpose(
            name=node.name+'_w_transpose',
            axes=W_transpose_axes,
            input_name=W_name,
            output_name=W_name+'_transposed',
        )
        W_name = W_name+'_transposed'
        node.inputs[1] = W_name

    params_dict['W'] = W
    bias = None
    if len(node.inputs) > 2:
        bias = node.input_tensors[node.inputs[2]]
    params_dict['bias'] = bias
    params_dict['groups'] = node.attrs.get("group", 1)

    _add_conv_like_op(_add_conv, _get_conv_params, params_dict,
                      builder, node, graph, err)
def _convert_conv ( builder , node , graph , err ) : params_dict = dict ( ) params_dict [ 'is_deconv' ] = False if node . op_type . endswith ( "Transpose" ) : params_dict [ 'is_deconv' ] = True #get weights for convolution weight_name = node . inputs [ 1 ] W = None if weight_name in node . input_tensors : W = node . input_tensors [ weight_name ] params_dict [ 'w_shape' ] = W . shape else : # W is provided as a input # Make W compatible for CoreML Conv Layer # W ONNX format: OC x KC x H x W # Expected CoreML Format: H x W x KC x OC W_name = node . inputs [ 1 ] W_shape = graph . shape_dict [ W_name ] W_rank = len ( W_shape ) params_dict [ 'w_shape' ] = W_shape if W_rank == 3 : expanded_node_name = node . name + '_' + W_name + '_expanded' builder . add_expand_dims ( name = node . name + '_w_expand' , input_name = W_name , output_name = expanded_node_name , axes = [ - 2 ] ) W_name = expanded_node_name # Now Permute the W tensor W_transpose_axes = [ 2 , 3 , 1 , 0 ] # If ConvTranpose then, Kernel and Output channels are shuffled if params_dict [ 'is_deconv' ] : W_transpose_axes = [ 2 , 3 , 0 , 1 ] builder . add_transpose ( name = node . name + '_w_transpose' , axes = W_transpose_axes , input_name = W_name , output_name = W_name + '_transposed' , ) W_name = W_name + '_transposed' node . inputs [ 1 ] = W_name params_dict [ 'W' ] = W bias = None if len ( node . inputs ) > 2 : bias = node . input_tensors [ node . inputs [ 2 ] ] params_dict [ 'bias' ] = bias params_dict [ 'groups' ] = node . attrs . get ( "group" , 1 ) _add_conv_like_op ( _add_conv , _get_conv_params , params_dict , builder , node , graph , err )