def consolidate_layers(layers, class_name_key=True, split_args=False):
    """For each of the layer dicts in `layers`, merge the dict's keys to reflect the end value of
    the key, rather than its default value, and whether a value was explicitly given

    Parameters
    ----------
    layers: List
        A list of dicts, wherein each dict represents a layer in a Keras model, and contains
        information about its arguments
    class_name_key: Boolean, default=True
        If True, "class_name" is added as a key to the dict describing each layer. Else, it will be
        used as a key to create an outer dict containing the rest of the keys describing each layer
    split_args: Boolean, default=False
        If True, each layer dict will be given two keys: "arg_vals", and "kwarg_vals", which are
        both dicts containing their respective values. Else, each layer dict will directly contain
        all the keys of "arg_vals", and "kwarg_vals", removing any indication of whether the
        parameter was a positional or keyword argument, aside from order

    Returns
    -------
    consolidated_layers: List
        A list of the same length as `layers`, except each element has fewer keys than it did in
        `layers`. The new keys are as follows: ["class_name", "arg_vals", "kwarg_vals"]"""
    consolidated_layers = []

    for layer in layers:
        arg_vals = {}

        #################### Gather Args ####################
        for i, expected_arg in enumerate(layer["__hh_default_args"]):
            try:
                arg_vals[expected_arg] = layer["__hh_used_args"][i]
            except IndexError:
                if expected_arg in layer["__hh_used_kwargs"]:
                    arg_vals[expected_arg] = layer["__hh_used_kwargs"][expected_arg]
                else:
                    raise

        #################### Gather Kwargs ####################
        # Merge default and used kwargs with constraints: only include if k in default, and give priority to used values
        # This means that kwargs like `input_shape` won't make it through because they have no default values, also
        # nonsensical kwargs won't make it through because the defaults are the point of reference
        kwarg_vals = {
            k: layer["__hh_used_kwargs"].get(k, v) for k, v in layer["__hh_default_kwargs"].items()
        }

        #################### Consolidate ####################
        if split_args:
            new_layer_dict = dict(arg_vals=arg_vals, kwarg_vals=kwarg_vals)
        else:
            new_layer_dict = {**arg_vals, **kwarg_vals}

        if class_name_key:
            new_layer_dict["class_name"] = layer["class_name"]
        else:
            new_layer_dict = {layer["class_name"]: new_layer_dict}

        consolidated_layers.append(new_layer_dict)
    return consolidated_layers