def _py_dict_to_cntk_dict(py_dict): ''' Converts a Python dictionary into a CNTK Dictionary whose values are CNTK DictionaryValue instances. Args: py_dict (dict): a dictionary to be converted. Returns: :class:`cntk_py.Dictionary` ''' res = cntk_py.Dictionary() for k, v in py_dict.items(): if isinstance(v, dict): res[k] = cntk_py.DictionaryValueFromDict(_py_dict_to_cntk_dict(v)) #TODO: add support to list of lists ? elif isinstance(v, list): l = list() for e in v: if isinstance(e, dict): l.append( cntk_py.DictionaryValueFromDict( _py_dict_to_cntk_dict(e))) else: l.append(cntk_py.DictionaryValue(v)) res[k] = cntk_py.DictionaryValue(l) else: res[k] = cntk_py.DictionaryValue(v) return res
def _get_checkpoint_state(self): state = self.get_checkpoint_state() d = cntk_py.Dictionary() for key, val in state.items(): if not is_string(key): raise ValueError('the keys of the checkpoint dictionary must ' 'be strings. You gave "%s" of type %s' % (key, type(key))) dv = cntk_py.DictionaryValue(val) d.add(key, dv) return d