Convert a GRU layer from keras to coreml.

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

    builder: NeuralNetworkBuilder
        A neural network builder object.

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

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

    builder: NeuralNetworkBuilder
        A neural network builder object.
    """

    hidden_size = keras_layer.output_dim
    input_size = keras_layer.input_shape[-1]

    output_all = keras_layer.return_sequences
    reverse_input = keras_layer.go_backwards

    if keras_layer.consume_less not in ['cpu', 'gpu']:
        raise ValueError('Cannot convert Keras layer with consume_less = %s' % keras_layer.consume_less)

    # Keras: Z R O
    # CoreML: Z R O
    W_h, W_x, b = ([], [], [])
    if keras_layer.consume_less == 'cpu':
        W_x.append(keras_layer.get_weights()[0].T)
        W_x.append(keras_layer.get_weights()[3].T)
        W_x.append(keras_layer.get_weights()[6].T)

        W_h.append(keras_layer.get_weights()[1].T)
        W_h.append(keras_layer.get_weights()[4].T)
        W_h.append(keras_layer.get_weights()[7].T)

        b.append(keras_layer.get_weights()[2])
        b.append(keras_layer.get_weights()[5])
        b.append(keras_layer.get_weights()[8])
    else:
        print('consume less not implemented')

    # Set actication type
    inner_activation_str = _get_recurrent_activation_name_from_keras(keras_layer.inner_activation)
    activation_str = _get_recurrent_activation_name_from_keras(keras_layer.activation)

    # Add to the network
    builder.add_gru(
       name = layer,
       W_h = W_h, W_x = W_x, b = b,
       input_size = input_size,
       hidden_size = hidden_size,
       input_names = input_names,
       output_names = output_names,
       activation = activation_str,
       inner_activation = inner_activation_str,
       output_all=output_all,
       reverse_input = reverse_input)