最新更新:在当前版本的Stream Analytics Job的公共审阅链接中,不支持ACI容器部署。因此,我将结束这个问题,直到另行通知。有关更多信息,请遵循下面发布的GitHub线程。
注:当Deployment值为ACI容器而不是AKS群集时,会出现此问题。使用Kubernetes群集,可以成功创建Azure ML服务功能。尽管我想使用ACI容器而不是AKS集群来测试我的功能。
我正在尝试在Stream Analytics Job服务中创建Azure ML服务功能。为此,我在Azure容器实例(也称为ACI)中使用了已经部署的ml模型。但是,出现此错误:
GitHub上的问题的link和related Microsoft document
尽管存在以下三个因素,仍存在此错误:
因素1:当我使用(ACI容器的)评分URL在本地(在Jupyter Notebook中)对某些值评分时,评分成功。因素2:我已经推断了score.py文件中输入数据的模式。因素3:我将infer-schema [numpy-support]模块作为对环境文件的依赖项。
我在做什么错?
ACI容器实例是使用授权(主)密钥部署的,另外,我在我的score.py文件中推断了输入和输出样本的模式。但是,Stream作业无法识别该swagger文件。由于我推断了score.py文件的模式,因此我read将自动生成swagger.json文件。
我的score.py文件的示例:
import json
import numpy as np
import os
import itertools
import joblib
from sklearn.ensemble import RandomForestRegressor
from azureml.core.model import Model
from inference_schema.schema_decorators import input_schema, output_schema
from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType
def init():
global model
# retrieve the path to the model file using the model name
model_path = Model.get_model_path('<model_name>')
model = joblib.load(model_path)
input_sample = np.array([["0", 0, 0, 0, 0, 0]])
output_sample = np.array([0])
@input_schema('raw_data', NumpyParameterType(input_sample))
@output_schema(NumpyParameterType(output_sample))
def run(raw_data):
try:
data = np.array(raw_data)
result=[]
for array in data:
prediction_result=model[array[0]].predict(array[1:].reshape(1,-1))
result.append(prediction_result.tolist())
result=list(itertools.chain.from_iterable(result))
# you can return any data type as long as it is JSON-serializable
return result
except Exception as e:
error = str(e)
return error
我的env.yml文件的示例:
name: project_environment
dependencies:
- python=3.7.3
- pip:
- azureml-defaults
- inference-schema[numpy-support]
- joblib
- numpy
- scikit-learn==0.20.3
对于解决此问题,我将不胜感激。
关键发现:
[我比较了AKS集群的aswagger.json文件和ACI容器实例的a。两个swagger文件之间的区别在于关键的“路径”。在AKS中,swagger.json中的路径为:“ paths”:{“ / api / v1 / service / aks-service /”:...。在ACI中,swagger.json中的路径为:“ paths”:{“ /”:.... etc
AKS集群的Swagger.json的一部分:
ACI群集的Swagger.json的一部分:
而且我认为这可能是问题的根源。也许Stream Analytics作业功能无法识别路径“ /”以自动生成ACI容器的功能签名。
我们首先从对AKS的支持开始,因为这是实时评分的推荐方法。由于此功能已在公众预览版中,我们正在为ACI上部署的模型确定一些性能基准,以便可以将其可靠地用于开发/测试目的。我们应该在接下来的几周内为ACI部署提供支持。