def load_model(): ivf = InvertedFiles() ivf_model = load_mat_with_cache(sett.cfg.COARSE_MODEL)["ivf"] pq_model_mat = load_mat_with_cache(sett.cfg.PQ_MODEL)["pq"] # ivf.quan = Quantizer.init_model_with_mat(pq_model_mat) ivf.quan = PQ.init_model_with_mat(pq_model_mat) ivf.codewords = ivf_model[0][0]["coa_centroids"] ivf.n_words = ivf_model[0][0]["coarsek"][0][0] return ivf
def search_exhasutive(imdb, keyword): categories = keyword.split(" ") cate_ids = [] for cate in categories: try: cate_id = PASCAL_CATEGORIES.index(cate) cate_ids.append(cate_id) except ValueError: pass if not cate_ids: cate_ids = [1] print (cate_ids) start_at = time.time() ivf = InvertedFiles.load_model() ivf.load_data() pq_model_mat = load_mat_with_cache(sett.cfg.PQ_MODEL)["pq"] # q = Quantizer.init_model_with_mat(pq_model_mat) q = PQ.init_model_with_mat(pq_model_mat) weights = load_mat_with_cache(sett.cfg.TRAINED_SVM)["weight"] ids = set() db = load_featdb() start_at = time.time() for cate_id in cate_ids: svm = weights[:, cate_id] if USE_IVF: idx = ivf.search_candidates(svm, 32) else: idx = pqsvm(svm, q, imdb) id_tmp = db["ids"][idx] if len(ids) == 0: ids = set(id_tmp) else: ids = ids.intersection(id_tmp) print ("IVF:{0}".format(time.time() - start_at)) + "[sec]" # ids = db['ids'][list(ids)] return list(ids)