diff --git a/deploy/configs/build_cartoon.yaml b/deploy/configs/build_cartoon.yaml index 3c93a6faa4f3c3f3e9e5a89eb7060ca265b29c9b..f739cde33eb6efbede67baf58c4ca5d7ace394bf 100644 --- a/deploy/configs/build_cartoon.yaml +++ b/deploy/configs/build_cartoon.yaml @@ -31,6 +31,7 @@ IndexProcess: index_path: "./recognition_demo_data_v1.0/gallery_cartoon/index/" image_root: "./recognition_demo_data_v1.0/gallery_cartoon/" data_file: "./recognition_demo_data_v1.0/gallery_cartoon/data_file.txt" + append_index: False delimiter: "\t" dist_type: "IP" pq_size: 100 diff --git a/deploy/configs/build_logo.yaml b/deploy/configs/build_logo.yaml index 1f3800e2750ccf3290732ac0c022379aedfb0c72..a806ec00606706d2609f50bac5247cb08ecac393 100644 --- a/deploy/configs/build_logo.yaml +++ b/deploy/configs/build_logo.yaml @@ -29,6 +29,7 @@ IndexProcess: index_path: "./recognition_demo_data_v1.0/gallery_logo/index/" image_root: "./recognition_demo_data_v1.0/gallery_logo/" data_file: "./recognition_demo_data_v1.0/gallery_logo/data_file.txt" + append_index: False delimiter: "\t" dist_type: "IP" pq_size: 100 diff --git a/deploy/configs/build_product.yaml b/deploy/configs/build_product.yaml index 1ae4c0d53542d4289290b5cf050f99ffc5c6b80a..679a1a6746612f5bc9c4734d9670a507e341a7fb 100644 --- a/deploy/configs/build_product.yaml +++ b/deploy/configs/build_product.yaml @@ -29,6 +29,7 @@ IndexProcess: index_path: "./recognition_demo_data_v1.0/gallery_product/index" image_root: "./recognition_demo_data_v1.0/gallery_product/" data_file: "./recognition_demo_data_v1.0/gallery_product/data_file.txt" + append_index: False delimiter: "\t" dist_type: "IP" pq_size: 100 diff --git a/deploy/configs/build_vehicle.yaml b/deploy/configs/build_vehicle.yaml index 4897f24a4ae7be533d28bc92224a230aac99679e..e149d938b88c07bfafdd6729730cf2599f6c9e4d 100644 --- a/deploy/configs/build_vehicle.yaml +++ b/deploy/configs/build_vehicle.yaml @@ -29,6 +29,7 @@ IndexProcess: index_path: "./recognition_demo_data_v1.0/gallery_vehicle/index/" image_root: "./recognition_demo_data_v1.0/gallery_vehicle/" data_file: "./recognition_demo_data_v1.0/gallery_vehicle/data_file.txt" + append_index: False delimiter: "\t" dist_type: "IP" pq_size: 100 diff --git a/deploy/python/build_gallery.py b/deploy/python/build_gallery.py index 2087d9e01b5ae778d9bb4ed46a1169dbca3d83c1..142e3cf23ca844f712ff996893cbac7a44589cc8 100644 --- a/deploy/python/build_gallery.py +++ b/deploy/python/build_gallery.py @@ -86,7 +86,8 @@ class GalleryBuilder(object): gallery_vectors=gallery_features, gallery_docs=gallery_docs, pq_size=config['pq_size'], - index_path=config['index_path']) + index_path=config['index_path'], + append_index=config["append_index"]) def main(config): diff --git a/deploy/vector_search/interface.py b/deploy/vector_search/interface.py index fd217304a5726e35e857e035e35f6e2c8d333ab5..8dcd86f55a3f16d895eb2b142e519896a67cef02 100644 --- a/deploy/vector_search/interface.py +++ b/deploy/vector_search/interface.py @@ -132,7 +132,8 @@ class Graph_Index(object): gallery_vectors, gallery_docs=[], pq_size=100, - index_path='graph_index/'): + index_path='graph_index/', + append_index=False): """ build index """ @@ -181,7 +182,25 @@ class Graph_Index(object): self.gallery_doc_dict["dist_type"] = self.dist_type self.gallery_doc_dict["with_attr"] = self.with_attr - with open(index_path + "/info.json", "w") as f: + output_path = os.path.join(index_path, "info.json") + if append_index is True and os.path.exists(output_path): + with open(output_path, "r") as fin: + lines = fin.readlines()[0] + ori_gallery_doc_dict = json.loads(lines) + assert ori_gallery_doc_dict["dist_type"] == self.gallery_doc_dict[ + "dist_type"] + assert ori_gallery_doc_dict["dim"] == self.gallery_doc_dict["dim"] + assert ori_gallery_doc_dict["with_attr"] == self.gallery_doc_dict[ + "with_attr"] + offset = ori_gallery_doc_dict["total_num"] + for i in range(0, self.gallery_doc_dict["total_num"]): + ori_gallery_doc_dict[str(i + offset)] = self.gallery_doc_dict[ + str(i)] + + ori_gallery_doc_dict["total_num"] += self.gallery_doc_dict[ + "total_num"] + self.gallery_doc_dict = ori_gallery_doc_dict + with open(output_path, "w") as f: json.dump(self.gallery_doc_dict, f) print("finished creating index ...")