def get_similar(image): db = Database() method = Color() samples = method.make_samples(db) # make sure image is ndarray query = { 'img': str(uuid.uuid1()), 'cls': 'TBD', 'hist': method.histogram(image) } _, result = infer(query, samples=samples) return [r['url'] for r in result]
for d in depths: APs = evaluate_class(db, f_instance=fusion, d_type=d_type, depth=d) cls_MAPs = [] for cls, cls_APs in APs.items(): MAP = np.mean(cls_APs) cls_MAPs.append(MAP) r = "{},{},{},{}".format(",".join(combination), d, d_type, np.mean(cls_MAPs)) print(r) result.write('\n' + r) print() result.close() if __name__ == "__main__": db = Database() # evaluate features double-wise evaluate_feats(db, N=2, d_type='d1') # evaluate features triple-wise evaluate_feats(db, N=3, d_type='d1') # evaluate features quadra-wise evaluate_feats(db, N=4, d_type='d1') # evaluate features penta-wise evaluate_feats(db, N=5, d_type='d1') # evaluate features hexa-wise evaluate_feats(db, N=6, d_type='d1')
continue samples.append({ 'img': d_img, 'cls': d_cls, 'url': d_url, 'hist': d_hist }) cPickle.dump( samples, open(os.path.join(cache_dir, sample_cache), "wb", True)) return samples if __name__ == "__main__": db = Database() data = db.get_data() color = Color() # test normalize print(os.path.join(DATASETS_PATH, data['cls'][0], data['img'][0])) hist = color.histogram(os.path.join(DATASETS_PATH, data['cls'][0], data['img'][0] + '.jpg'), type='global') assert hist.sum() - 1 < 1e-9, "normalize false" # test histogram bins def sigmoid(z): a = 1.0 / (1.0 + np.exp(-1. * z)) return a