diff --git a/panoptic_back/panoptic/plugins/FaissPlugin/faiss_plugin.py b/panoptic_back/panoptic/plugins/FaissPlugin/faiss_plugin.py index 762dffb7..389bb479 100644 --- a/panoptic_back/panoptic/plugins/FaissPlugin/faiss_plugin.py +++ b/panoptic_back/panoptic/plugins/FaissPlugin/faiss_plugin.py @@ -1,3 +1,5 @@ +import os.path + from pydantic import BaseModel from panoptic.core.project.project import Project @@ -35,6 +37,16 @@ def __init__(self, project: Project, plugin_path: str): project.action.find_images.register(self, self.find_images) project.action.group_images.register(self, self.compute_clusters) + async def start(self): + await super().start() + vectors = await self.project.db.get_vectors(self.name, 'clip') + + # TODO: handle this properly with an import hook + if not os.path.exists(os.path.join(self.project.base_path, 'tree_faiss.pkl')) and len(vectors) > 0: + from panoptic.plugins.FaissPlugin.create_faiss_index import compute_faiss_index + await compute_faiss_index(self.project.base_path, self.project.db, self.name, 'clip') + reload_tree(self.project.base_path) + async def compute_image_vector(self, instance: Instance): task = ComputeVectorTask(self.project, self.name, 'clip', instance) self.project.task_queue.add_task(task)