def convert_permute(builder, layer, input_names, output_names, keras_layer):
    """Convert a softmax layer from keras to coreml.

    Parameters
    keras_layer: layer
    ----------
        A keras layer object.

    builder: NeuralNetworkBuilder
        A neural network builder object.
    """
    input_name, output_name = (input_names[0], output_names[0])

    keras_dims = keras_layer.dims
    # Keras permute layer index begins at 1
    if len(keras_dims) == 3:
        # Keras input tensor interpret as (H,W,C)
        x = list(np.array(keras_dims))
        i1, i2, i3 = x.index(1), x.index(2), x.index(3)
        x[i1], x[i2], x[i3] = 2, 3, 1
        # add a sequence axis
        x = [0] + x
        dim = tuple(x)
    elif len(keras_dims) == 4:
        # Here we use Keras converter as a place holder for inserting
        # permutations - the values here are not valid Keras dim parameters
        # but parameters we need to use to convert to CoreML model
        dim = keras_dims
    else:
        raise NotImplementedError('Supports only 3d permutation.')

    builder.add_permute(name = layer, dim=dim, input_name = input_name,
            output_name = output_name)