def get_symbolic_weight_names(layer, weights=None):
    """Attribute names for weights

    Looks up the attribute names of weight tensors.

    :param layer: Targeted layer.
    :param weights: A list of weight tensors.
    :return: The attribute names of the weights.
    """
    if weights is None:
        weights = layer.weights
    good_guesses = ['kernel', 'bias', 'gamma', 'beta', 'moving_mean',
        'moving_variance', 'depthwise_kernel', 'pointwise_kernel']
    ret = []
    for weight in weights:
        for attr_name in (good_guesses + dir(layer)):
            if hasattr(layer, attr_name) and id(weight) == id(getattr(layer,
                attr_name)):
                ret.append(attr_name)
                break
    if len(weights) != len(ret):
        raise Exception('Could not find symoblic weight name(s).')
    return ret
