Esempio n. 1
0
    def get_retriever(cls, retriever_pk):
        if retriever_pk not in cls._visual_retriever:
            dr = Retriever.objects.get(pk=retriever_pk)
            cls._retriever_object[retriever_pk] = dr
            if dr.algorithm == Retriever.EXACT and dr.approximator_shasum and dr.approximator_shasum.strip():
                approximator, da = Approximators.get_approximator_by_shasum(dr.approximator_shasum)
                da.ensure()
                approximator.load()
                cls._visual_retriever[retriever_pk] = retriever.BaseRetriever(name=dr.name, approximator=approximator)
            elif dr.algorithm == Retriever.EXACT:
                cls._visual_retriever[retriever_pk] = retriever.BaseRetriever(name=dr.name)
            elif dr.algorithm == Retriever.FAISS and dr.approximator_shasum is None:
                di = Indexers.get_indexer_by_shasum(dr.indexer_shasum)
                cls._visual_retriever[retriever_pk] = retriever.FaissFlatRetriever(name=dr.name,
                                                                                   components=di.arguments[
                                                                                       'components'])
            elif dr.algorithm == Retriever.FAISS:
                approximator, da = Approximators.get_approximator_by_shasum(dr.approximator_shasum)
                da.ensure()
                approximator.load()
                cls._visual_retriever[retriever_pk] = retriever.FaissApproximateRetriever(name=dr.name,
                                                                                          approximator=approximator)
            elif dr.algorithm == Retriever.LOPQ:
                approximator, da = Approximators.get_approximator_by_shasum(dr.approximator_shasum)
                da.ensure()
                approximator.load()
                cls._visual_retriever[retriever_pk] = retriever.LOPQRetriever(name=dr.name,
                                                                              approximator=approximator)

            else:
                raise ValueError("{} not valid retriever algorithm".format(dr.algorithm))
        return cls._visual_retriever[retriever_pk], cls._retriever_object[retriever_pk]
Esempio n. 2
0
    def get_retriever(cls, retriever_pk):
        if retriever_pk not in cls._visual_retriever:
            dr = Retriever.objects.get(pk=retriever_pk)
            cls._retriever_object[retriever_pk] = dr
            if dr.algorithm == Retriever.EXACT and dr.approximator_shasum and dr.approximator_shasum.strip(
            ):
                approximator, da = Approximators.get_approximator_by_shasum(
                    dr.approximator_shasum)
                da.ensure()
                approximator.load()
                cls._visual_retriever[retriever_pk] = retriever.BaseRetriever(
                    name=dr.name, approximator=approximator)
            elif dr.algorithm == Retriever.EXACT:
                cls._visual_retriever[retriever_pk] = retriever.BaseRetriever(
                    name=dr.name)
            elif dr.algorithm == Retriever.LOPQ:
                approximator, da = Approximators.get_approximator_by_shasum(
                    dr.approximator_shasum)
                da.ensure()
                approximator.load()
                cls._visual_retriever[retriever_pk] = retriever.LOPQRetriever(
                    name=dr.name, approximator=approximator)

            else:
                raise ValueError, "{} not valid retriever algorithm".format(
                    dr.algorithm)
        return cls._visual_retriever[retriever_pk], cls._retriever_object[
            retriever_pk]
Esempio n. 3
0
 def visual_retriever(self):
     if RetrieverTask._visual_retriever is None:
         RetrieverTask._visual_retriever = {
             'inception': retriever.BaseRetriever(name="inception"),
             'vgg': retriever.BaseRetriever(name="vgg"),
             'facenet': retriever.BaseRetriever(name="facenet")
         }
     return RetrieverTask._visual_retriever
 def get_retriever(self,retriever_pk):
     if retriever_pk not in RetrieverTask._visual_retriever:
         dr = Retriever.objects.get(pk=retriever_pk)
         RetrieverTask._retriever_object[retriever_pk] = dr
         if dr.algorithm == Retriever.EXACT:
             RetrieverTask._visual_retriever[retriever_pk] = retriever.BaseRetriever(name=dr.name)
         elif dr.algorithm == Retriever.LOPQ:
             dr.arguments['proto_filename'] = dr.proto_filename()
             RetrieverTask._visual_retriever[retriever_pk] = retriever.LOPQRetriever(name=dr.name,args=dr.arguments)
             RetrieverTask._visual_retriever[retriever_pk].load()
         else:
             raise ValueError,"{} not valid retriever algorithm".format(dr.algorithm)
     return RetrieverTask._visual_retriever[retriever_pk], RetrieverTask._retriever_object[retriever_pk]
Esempio n. 5
0
 def get_retriever(self, dr):
     if dr.pk not in RetrieverTask._visual_retriever:
         RetrieverTask._visual_retriever[dr.pk] = retriever.BaseRetriever(
             name=dr.name)
     return RetrieverTask._visual_retriever[dr.pk]