예제 #1
0
def pipeline_ilegal(pipe):
    registed_operators = [
        x for x in all_operators() if x.type == OPERATOR_TYPE_ENCODER
    ]
    for op in registed_operators:
        if pipe.encoder == op.name:
            if pipe.dimension == op.dimension and pipe.metric_type == op.metric_type:
                return False
    return True
예제 #2
0
def run_pipeline(p, **kwargs):
    todo_list = []
    if not isinstance(p, Pipeline):
        raise PipelineCheckError("check pipeline with error",
                                 "%s is not a Pipeline instance" % p)
    operators = all_operators()
    processor_operators = {
        x.name: x
        for x in operators if x.type == OPERATOR_TYPE_PROCESSOR
    }
    encoder_operators = {
        x.name: x
        for x in operators if x.type == OPERATOR_TYPE_ENCODER
    }
    for i in p.processors:
        if i not in processor_operators:
            raise PipelineCheckError(
                "processors not exist",
                "%s not exist in supported processors " % i)
        todo_list.append(processor_operators[i])
    if p.encoder not in encoder_operators:
        raise PipelineCheckError(
            "encoder not exist",
            "%s not exist in supported encoders" % p.encoder)
    todo_list.append(encoder_operators[p.encoder])

    def runner(todo_list):
        metadata, vectors = [], []
        urls = [kwargs['url']] if kwargs['url'] else []
        datas = [kwargs['data']] if kwargs['data'] else []
        try:
            for i in todo_list:
                if i.type == "processor":
                    _, metadatas = execute(i, urls=urls, datas=datas)
                    urls = [x.url for x in metadatas]
                    datas = [x.data for x in metadatas]
                if i.type == "encoder":
                    vectors, _ = execute(i, urls=urls, datas=datas)
                    return vectors
            return metadata
        except Exception as e:
            raise RPCExecError("Execute with error", e)

    try:
        return runner(todo_list)
    except Exception as e:
        logger.error(e)
        raise e
예제 #3
0
def operator_list_api():
    return all_operators()