(builder, node, graph, err)
convert to CoreML ReduceSum Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L4707
convert to CoreML ReduceSum Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L4707
convert to CoreML ReduceSum Layer : https : // github . com / apple / coremltools / blob / 655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492 / mlmodel / format / NeuralNetwork . proto#L4707
def _convert_reduce(builder, node, graph, err):
    '''
    convert to CoreML ReduceSum Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L4707
    '''
    load_input_constants(builder, node, graph, err)

    # read attributes
    axes = node.attrs.get('axes', None)
    reduce_all = False
    if axes is None:
        reduce_all = True
    keepdims = node.attrs.get('keepdims', True)

    # add respective operator
    op_type = node.op_type
    if op_type == 'ReduceSum':
        builder.add_reduce_sum(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceProd':
        builder.add_reduce_prod(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceMean':
        builder.add_reduce_mean(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceMax':
        builder.add_reduce_max(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceMin':
        builder.add_reduce_min(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceL2':
        builder.add_reduce_l2(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceL1':
        builder.add_reduce_l1(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceSumSquare':
        builder.add_reduce_sumsquare(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceLogSum':
        builder.add_reduce_logsum(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    elif op_type == 'ReduceLogSumExp':
        builder.add_reduce_logsumexp(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            axes=axes,
            keepdims=keepdims,
            reduce_all=reduce_all
        )
    else:
        err.unsupported_op_configuration(builder, node, graph, "Unsupported reduce operation: {}".format(op_type))
def _convert_reduce ( builder , node , graph , err ) : load_input_constants ( builder , node , graph , err ) # read attributes axes = node . attrs . get ( 'axes' , None ) reduce_all = False if axes is None : reduce_all = True keepdims = node . attrs . get ( 'keepdims' , True ) # add respective operator op_type = node . op_type if op_type == 'ReduceSum' : builder . add_reduce_sum ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceProd' : builder . add_reduce_prod ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceMean' : builder . add_reduce_mean ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceMax' : builder . add_reduce_max ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceMin' : builder . add_reduce_min ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceL2' : builder . add_reduce_l2 ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceL1' : builder . add_reduce_l1 ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceSumSquare' : builder . add_reduce_sumsquare ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceLogSum' : builder . add_reduce_logsum ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) elif op_type == 'ReduceLogSumExp' : builder . add_reduce_logsumexp ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , axes = axes , keepdims = keepdims , reduce_all = reduce_all ) else : err . unsupported_op_configuration ( builder , node , graph , "Unsupported reduce operation: {}" . format ( op_type ) )