def find_layer(model, type, order=0):
    """
    Given a model, find the Nth layer of the specified type.
    :param model: the model that will be searched
    :param type:  the lowercase type, as it is automatically saved by keras in the layer's name (e.g. conv2d, dense)
    :param order: 0 by default (the first matching layer will be returned)
    :return: The index of the matching layer or None if it was not found.
    """
    num_found = 0
    for layer in model.layers:
        if type + '_' in layer.get_config()['name']:
            if order == num_found:
                return layer

            num_found += 1
    return None