def hyperopt_rval(self, save_grams): rval = copy.deepcopy(self._results) rval['attachments'] = {} rval['grams'] = {} rval['weights'] = {} rval['trace'] = copy.deepcopy(foobar._trace) saved = set() def jsonify_train_results(rkey): for norm_key in rval[rkey]: for task_name in rval[rkey][norm_key]: svm_dct = rval[rkey][norm_key][task_name] ens = svm_dct.pop('ens') rval['weights'].setdefault(norm_key, {}) rval['weights'][norm_key][task_name] = ens._weights # -- stash these as attachments because they fill up the db. xmean = svm_dct.pop('xmean') xstd = svm_dct.pop('xstd') if save_grams: xmean_key = 'xmean_%s_%s_%s' % (rkey, norm_key, task_name) xstd_key = 'xstd_%s_%s_%s' % (rkey, norm_key, task_name) rval['attachments'][xmean_key] = cPickle.dumps(xmean, -1) rval['attachments'][xstd_key] = cPickle.dumps(xstd, -1) rval['grams'].setdefault(norm_key, []) for (inorm_key, sample1, sample2) in ens._grams: if inorm_key != norm_key: # -- we're only interested in saving the grams # calculated by this run. continue if (norm_key, sample1, sample2) in saved: # -- already saved this one continue att_key = 'gram_%s_%s_%s.pkl' % ( norm_key, sample1, sample2) info('saving %s' % att_key) gram = ens._grams[(norm_key, sample1, sample2)] rval['attachments'][att_key] = dumps_gram( gram.astype('float32')) rval['grams'][norm_key].append((sample1, sample2)) saved.add((norm_key, sample1, sample2)) saved.add((norm_key, sample2, sample1)) jsonify_train_results('train_image_match_indexed') jsonify_train_results('retrain_classifier_image_match_indexed') return SONify(rval)
def SONify(self, foo): rval = SONify(foo) assert bson.BSON.encode(dict(a=rval)) return rval
def test_nested_w_bool(self): thing = dict(a=1, b='2', c=True, d=False, e=np.int(3), f=[1l]) assert thing == SONify(thing)
def test_nested_w_bool(self): thing = dict(a=1, b="2", c=True, d=False, e=int(3), f=[1]) assert thing == SONify(thing)