我在Google顶点AI中有多个模型,我想创建一个端点来为我的预测服务。我需要运行聚合算法,比如在我的模型输出上的投票算法。我还没有找到任何方法将模型放在一起,这样我就可以在结果上运行投票算法。我是否必须创建一个新的模型,卷曲我现有的模型,然后对结果运行我的算法?
发布于 2022-03-22 11:53:45
在顶点AI中没有实现聚合算法的内置条款.要将来自模型的curl结果聚合起来,我们需要将它们全部部署到各个端点。相反,我建议使用以下方法使用用于预测的定制容器将模型和元模型(聚合模型)部署到单个端点。可以找到自定义容器需求这里。
可以将模型构件从GCS加载到自定义容器中。如果使用相同的模型集(即:对元模型的输入模型不改变),则可以将它们封装在容器中以减少加载时间。然后,可以使用自定义HTTP逻辑来返回聚合输出,如下所示。这是一个示例自定义烧瓶服务器逻辑。
def get_models_from_gcs():
## Pull the required model artifacts from GCS and load them here.
models = [model_1, model_2, model_3]
return models
def aggregate_predictions(predictions):
## Your aggregation algorithm here
return aggregated_result
@app.post(os.environ['AIP_PREDICT_ROUTE'])
async def predict(request: Request):
body = await request.json()
instances = body["instances"]
inputs = np.asarray(instances)
preprocessed_inputs = _preprocessor.preprocess(inputs)
models = get_models_from_gcs()
predictions = []
for model in models:
predictions.append(model.predict(preprocessed_inputs))
aggregated_result = aggregate_predictions(predictions)
return {"aggregated_predictions": aggregated_result}https://stackoverflow.com/questions/71557442
复制相似问题