def weight_name_to_layer_name(weight_name):
    """ Convert the name of weights to the layer name """
    tokens = weight_name.split('_')
    type_name = tokens[-1]

    # modern naming convention
    if type_name == 'weights' or type_name == 'bias':
        if len(tokens) >= 3 and tokens[-3] == 'input':
            return weight_name[:weight_name.rfind('input')-1]            
        return weight_name[:weight_name.rfind(type_name)-1]
    # legacy
    if type_name == 'im':
        return weight_name[:-4]
    if type_name == 'pose':
        return weight_name[:-6]
    return weight_name[:-1]