(builder, node, graph, err)
convert to CoreML Slice Static Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L5082
convert to CoreML Slice Static Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L5082
convert to CoreML Slice Static Layer : https : // github . com / apple / coremltools / blob / 655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492 / mlmodel / format / NeuralNetwork . proto#L5082
def _convert_slice(builder, node, graph, err):
    '''
    convert to CoreML Slice Static Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L5082
    ''' 
    if len(node.inputs) == 1:
       return _convert_slice_ir4v9(builder, node, graph, err)

    if node.inputs[0] not in graph.shape_dict:
        err.unsupported_op_configuration(builder, node, graph, "Input shape not available")

    data_shape = graph.shape_dict[node.inputs[0]]
    len_of_data = len(data_shape)
    begin_masks = [True] * len_of_data
    end_masks = [True] * len_of_data

    default_axes = list(range(len_of_data))

    add_static_slice_layer = False
    if node.inputs[1] in node.input_tensors and node.inputs[2] in node.input_tensors:
        if len(node.inputs) > 3:
            if node.inputs[3] in node.input_tensors:
                if len(node.inputs) > 4:
                    if node.inputs[4] in node.input_tensors:
                        add_static_slice_layer = True
                else:
                    add_static_slice_layer = True
        else:
            add_static_slice_layer = True

    if add_static_slice_layer:
        ip_starts = node.input_tensors[node.inputs[1]]
        ip_ends   = node.input_tensors[node.inputs[2]]
        axes  = node.input_tensors[node.inputs[3]] if len(node.inputs) > 3 else default_axes
        ip_steps  = node.input_tensors[node.inputs[4]] if len(node.inputs) > 4 else None
        
        starts = [0] * len_of_data
        ends = [0] * len_of_data
        steps = [1] * len_of_data

        for i in range(len(axes)):
            current_axes = axes[i]
            starts[current_axes] = ip_starts[i]
            ends[current_axes] = ip_ends[i]
            # n <= end <= INT_MAX implies end is -1, hence end_mask should be True
            # otherwise end_mask should be False
            if ends[current_axes] < data_shape[current_axes]:
                # this means end is not -1
                end_masks[current_axes] = False

            if starts[current_axes] != 0:
                begin_masks[current_axes] = False

            if isinstance(ip_steps, list):
                steps[current_axes] = ip_steps[i]

        builder.add_slice_static(
            name=node.name,
            input_name=node.inputs[0],
            output_name=node.outputs[0],
            begin_ids=starts,
            end_ids=ends,
            strides=steps,
            begin_masks=begin_masks,
            end_masks=end_masks
        )
    else:
        err.unsupported_op_configuration(builder, node, graph, "CoreML does not support Dynamic Slice with unknown axes. Please provide Custom Function/Layer")
def _convert_slice ( builder , node , graph , err ) : if len ( node . inputs ) == 1 : return _convert_slice_ir4v9 ( builder , node , graph , err ) if node . inputs [ 0 ] not in graph . shape_dict : err . unsupported_op_configuration ( builder , node , graph , "Input shape not available" ) data_shape = graph . shape_dict [ node . inputs [ 0 ] ] len_of_data = len ( data_shape ) begin_masks = [ True ] * len_of_data end_masks = [ True ] * len_of_data default_axes = list ( range ( len_of_data ) ) add_static_slice_layer = False if node . inputs [ 1 ] in node . input_tensors and node . inputs [ 2 ] in node . input_tensors : if len ( node . inputs ) > 3 : if node . inputs [ 3 ] in node . input_tensors : if len ( node . inputs ) > 4 : if node . inputs [ 4 ] in node . input_tensors : add_static_slice_layer = True else : add_static_slice_layer = True else : add_static_slice_layer = True if add_static_slice_layer : ip_starts = node . input_tensors [ node . inputs [ 1 ] ] ip_ends = node . input_tensors [ node . inputs [ 2 ] ] axes = node . input_tensors [ node . inputs [ 3 ] ] if len ( node . inputs ) > 3 else default_axes ip_steps = node . input_tensors [ node . inputs [ 4 ] ] if len ( node . inputs ) > 4 else None starts = [ 0 ] * len_of_data ends = [ 0 ] * len_of_data steps = [ 1 ] * len_of_data for i in range ( len ( axes ) ) : current_axes = axes [ i ] starts [ current_axes ] = ip_starts [ i ] ends [ current_axes ] = ip_ends [ i ] # n <= end <= INT_MAX implies end is -1, hence end_mask should be True # otherwise end_mask should be False if ends [ current_axes ] < data_shape [ current_axes ] : # this means end is not -1 end_masks [ current_axes ] = False if starts [ current_axes ] != 0 : begin_masks [ current_axes ] = False if isinstance ( ip_steps , list ) : steps [ current_axes ] = ip_steps [ i ] builder . add_slice_static ( name = node . name , input_name = node . inputs [ 0 ] , output_name = node . outputs [ 0 ] , begin_ids = starts , end_ids = ends , strides = steps , begin_masks = begin_masks , end_masks = end_masks ) else : err . unsupported_op_configuration ( builder , node , graph , "CoreML does not support Dynamic Slice with unknown axes. Please provide Custom Function/Layer" )