0

Is it possible to group tensorflow FLAGS by type? E.g. Some flags are system related (e.g. # of threads) while others are model hyperparams.

Then, is it possible to use the model hyperparams FLAGS, in order to generate a string? (the string will be used to identify the model filename)

Thanks

Yuval Atzmon
  • 5,645
  • 3
  • 41
  • 74

2 Answers2

0

I'm guessing that you're wanting to automatically store the hyper-parameters as part of the file name in order to organize your experiments better? Unfortunately there isn't a good way to do this with TensorFlow, but you can look at some of the high-level frameworks built on top of it to see if they offer something similar.

Pete Warden
  • 2,866
  • 1
  • 13
  • 12
0

I eventually managed to do it by treating the FLAGS object as a dictionary, and then flattening the dictionary to a string of key=value.

Here is the code:

def build_string_from_dict(d, sep='__'):
    fd = _flatten_dict(d)
    return sep.join(['{}={}'.format(k, _value2str(fd[k])) for k in sorted(fd.keys())])

def _flatten_dict(d, parent_key='', sep='_'):
    # from http://stackoverflow.com/a/6027615/2476373
    items = []
    for k, v in d.items():
        new_key = parent_key + sep + k if parent_key else k
        if isinstance(v, collections.MutableMapping):
            items.extend(_flatten_dict(v, new_key, sep=sep).items())
        else:
            items.append((new_key, v))
    return dict(items)


flags_dict = vars(FLAGS)['__flags']
print build_string_from_dict(flags_dict)
Yuval Atzmon
  • 5,645
  • 3
  • 41
  • 74