Exemplo n.º 1
0
def compact_idstr(dict_):
    """
    A short unique id string for a dict param config that is semi-interpretable
    """
    from clab import util
    import ubelt as ub
    short_keys = util.shortest_unique_prefixes(dict_.keys())
    short_dict = ub.odict(sorted(zip(short_keys, dict_.values())))
    idstr = ub.repr2(short_dict, nobr=1, itemsep='', si=1, nl=0, explicit=1)
    return idstr
Exemplo n.º 2
0
def make_short_idstr(params, precision=None):
    """
    Make id-string where they keys are shortened

    Args:
        params (dict):

    Returns:
        str:

    CommandLine:
        python -m clab.util.misc make_short_idstr

    Example:
        >>> from clab.util.misc import *  # NOQA
        >>> params = {'input_shape': (None, 3, 212, 212),
        >>>           'a': 'b',
        >>>           'center': {'im_mean': .5, 'std': 1},
        >>>           'alphabet': 'abc'}
        >>> print(make_short_idstr(params))
    """
    if params is None:
        return ''
    elif len(params) == 0:
        return ''
    from clab import util
    short_keys = util.shortest_unique_prefixes(list(params.keys()),
                                               allow_simple=False,
                                               allow_end=True,
                                               min_length=1)

    def shortval(v):
        if isinstance(v, bool):
            return int(v)
        return v

    d = dict(zip(short_keys, map(shortval, params.values())))

    def make_idstr(d):
        # Note: we are not using sort=True, because repr2 sorts sets and dicts
        # by default.
        return ub.repr2(d,
                        itemsep='',
                        nobr=True,
                        explicit=True,
                        nl=0,
                        si=True,
                        precision=precision).replace(' ', '').replace(
                            '[', '').replace(']', '').replace('(', '').replace(
                                ')', '').replace('{', '').replace('}', '')

    short_idstr = make_idstr(d)
    return short_idstr
Exemplo n.º 3
0
 def other_id(hyper):
     """
         >>> from clab.torch.hyperparams import *
         >>> hyper = HyperParams(other={'augment': True, 'n_classes': 10, 'n_channels': 5})
         >>> hyper.hyper_id()
     """
     short_keys = util.shortest_unique_prefixes(list(hyper.other.keys()))
     def shortval(v):
         if isinstance(v, bool):
             return int(v)
         return v
     d = dict(zip(short_keys, map(shortval, hyper.other.values())))
     def make_idstr(d):
         return ub.repr2(d, itemsep='', nobr=True, explicit=True, nl=0,
                         si=True, sort=True)
     otherid = make_idstr(d)
     return otherid