def test_fg11_top_bandit(): L = lfw.FG11Bandit() config = stochastic.sample(L.template, np.random.RandomState(0)) config['decisions'] = None config['slm'] = stochastic.sample(pyll.as_apply(params.fg11_top), np.random.RandomState(0)) config['comparison'] = 'sqrtabsdiff' rec = L.evaluate(config, hyperopt.base.Ctrl(None)) assert np.abs(rec['loss'] - .194) < 1e-2 return rec
def get_oneobj_latents(tdict, models, categories): rng = np.random.RandomState(seed=int(clock())) latents = [] tname = tdict['name'] template = tdict['template'] n_ex = tdict['n_ex'] for model in models: for _ind in range(n_ex): l = stochastic.sample(template, rng) l['obj'] = [model] l['category'] = [categories[model][0]] l['id'] = get_image_id(l) rec = (l['bgname'], float(l['bgphi']), float(l['bgpsi']), float(l['bgscale']), l['category'], l['obj'], [float(l['ryz'])], [float(l['rxz'])], [float(l['rxy'])], [float(l['ty'])], [float(l['tz'])], [float(l['tx'])], [float(l['s'])], [None], [None], tname, l['id']) latents.append(rec) return latents
def get_oneobj_latents(tdict, models, categories): rng = np.random.RandomState(seed=int(clock())) latents = [] tname = tdict["name"] template = tdict["template"] n_ex = tdict["n_ex"] for model in models: for _ind in range(n_ex): l = stochastic.sample(template, rng) l["obj"] = [model] l["category"] = [categories[model][0]] l["id"] = get_image_id(l) rec = ( l["bgname"], float(l["bgphi"]), float(l["bgpsi"]), float(l["bgscale"]), l["category"], l["obj"], [float(l["ryz"])], [float(l["rxz"])], [float(l["rxy"])], [float(l["ty"])], [float(l["tz"])], [float(l["tx"])], [float(l["s"])], [None], [None], tname, l["id"], ) latents.append(rec) return latents
def get_textured_oneobj_latents(tdict, models, categories): rng = np.random.RandomState(seed=0) latents = [] tname = tdict['name'] template = tdict['template'] n_ex = tdict['n_ex'] for model in models: # print('Generating meta for %s' % model) for _ind in range(n_ex): l = stochastic.sample(template, rng) l['obj'] = [model] l['category'] = [categories[model][0]] l['id'] = model + str(_ind) rec = (l['bgname'], float(l['bgphi']), float(l['bgpsi']), float(l['bgscale']), l['category'], l['obj'], [float(l['ryz'])], [float(l['rxz'])], [float(l['rxy'])], [float(l['ty'])], [float(l['tz'])], [float(l['tx'])], [float(l['s'])], l['texture'], [float(l['texture_mode'])], tname, l['id']) latents.append(rec) return latents
def get_canon_latents(tdict, models, categories): rng = np.random.RandomState(seed=int(clock())) latents = [] tname = tdict['name'] template = tdict['template'] n_ex = tdict['n_ex'] for model in models: objmodel = obj.REVERSED_OBJECT_DICT[model] for _ind in range(n_ex): lr = obj.get_canonical_angle(model) lr['s'] = obj.CANONICAL_SIZES[objmodel] / 100.0 l = stochastic.sample(template, rng) l['obj'] = [model] l['category'] = [categories[model][0]] l['id'] = objmodel + '_nolabel' rec = (l['bgname'], float(l['bgphi']), float(l['bgpsi']), float(l['bgscale']), l['category'], l['obj'], [float(lr['ryz'])], [float(lr['rxz'])], [float(lr['rxy'])], [float(l['ty'])], [float(l['tz'])], [float(l['tx'])], [float(lr['s'])], l.get('texture'), l.get('texture_mode'), tname, l['id']) latents.append(rec) return latents
def forint(self, seed): config = stochastic.sample( dict( slm=[[params.pf_lnorm()]], preproc=params.pf_preproc()[1]), np.random.RandomState(seed)) fuzz_config(config)
def test_main_bandit(): L = lfw.MainBandit() config = stochastic.sample(L.template, np.random.RandomState(999)) print config['model']['slm'][0] assert np.allclose( config['model']['slm'][0][0][1]['kwargs']['threshold'], 16.894686245715995) rec = L.evaluate(config, hyperopt.base.Ctrl(None)) print rec['test_accuracy'] print rec['train_accuracy'] print rec['loss'] assert np.allclose(rec['test_accuracy'], 58.3) assert np.allclose(rec['train_accuracy'], 84.9090909091) assert np.allclose(rec['loss'], 0.417) return rec
def get_multiobj_latents(tdict, models, categories): rng = np.random.RandomState(seed=int(clock())) latents = [] tname = tdict['name'] template = tdict['template'] n_ex = tdict['n_ex'] n_obj = 2 model_tuples = list(itertools.combinations(models, n_obj)) for models in model_tuples: model1 = models[0] model2 = models[1] for _ind in range(n_ex): l = stochastic.sample(template, rng) OBJS = [model1, model2] rng.shuffle(OBJS) CATS = [categories[model1][0], categories[model2][0]] imgid = get_image_id(l) rec = (l['bgname'], float(l['bgphi']), float(l['bgpsi']), float(l['bgscale']), CATS, OBJS, [float(i) for i in l['ryz']], [float(i) for i in l['rxz']], [float(i) for i in l['rxy']], [float(i) for i in l['ty']], [float(i) for i in l['tz']], [float(i) for i in l['tx']], [float(i) for i in l['s']], [None, None], [None, None], tname, imgid ) latents.append(rec) return latents
def forint(self, seed): L = lfw.MainBandit() config = stochastic.sample(L.template, np.random.RandomState(seed)) fuzz_config(config['model'])
import hyperopt import hyperopt.base import eccv12.lfw as lfw import eccv12.bandits as bandits import eccv12.experiments as experiments import os test_params = { 'slm': [[('lnorm', params.lnorm)]], 'preproc': { 'global_normalize': 0, 'crop': params.crop_choice, 'size': [20, 20]}} config_tiny_rnd0 = stochastic.sample( test_params, np.random.RandomState(0)) config_tiny_rnd2 = stochastic.sample( test_params, np.random.RandomState(2)) def test_sampling_lockdown(): """ Test that pyll samples the same way as when we ran these experiments. """ # done with commit # f11026e235e57f85e9dd4f3a23a67dac2b33e8db print config_tiny_rnd0 print config_tiny_rnd2 assert config_tiny_rnd0 == {