def get_weights(model, key=None):
    """
        Copy the model's weights into a dictionary, filtering on the name if a key is provided

        Arguments:
            model: The model to save weights from
            key: The key on which to filter the saved weights, only layers containing the key in their name are saved
    """
    weight_dic = {}
    for layer in model.layers:
        if key and key in layer.name:
            weight_dic[layer.name] = layer.get_weights()
    return weight_dic