我们有一个Azure机器学习Web服务,可以从C#程序中调用它。当作为HTML帖子(在正文中包含Headers和JSON字符串)调用时,它可以正常工作。但是,在Azure流分析中,您必须创建一个函数来调用ML服务。当在ASA中调用此功能时,它会因请求错误而失败。
ML服务的文档提供了以下文档:
请求正文 样品申请
{
"Inputs":{
"input":[
{
"device":"60-1-94-49-36-c5",
"uid":"5f4736aabfc1312385ea09805cc922",
"weight":"9-9-9-9-9-8-9-8-9-9-9-9-9-9-9-9-9-8-9-9-8-8-9-9-9-9-9-
9-9-9-9-9-9-9-8-9-9-9-9-9-9-9-9-9-9-9-9-9-8-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-
9-9-8-9-9-9-9-8-9-9-9-8-9-9-9-9-9-9-9-9-9-8-9-9-9-9-8-8-16-16-15-16-16-15-
15-16-15-15-15-15-16-15-15-16-15-15-9-15-15-15-15-15-15-15-9-15-16-15-15-9-
15-16-16-16-15-15-15-15-15-15-15-15-16-16-15-9-15-15-15-16-15-16-15-15-15-
15-15-16-15-15-16-16-15-15-15"
}
]
},
"GlobalParameters":{
}
}
Azure流分析功能(调用上面的ML服务)具有以下签名:
FUNCTION SIGNATURE
SmartStokML2018Aug17 ( device NVARCHAR(MAX) ,
uid NVARCHAR(MAX) ,
weight NVARCHAR(MAX) ) RETURNS RECORD
此处函数需要3个字符串参数,而不是完整的JSON字符串。这三个参数是字符串(显示为NVARCHAR)。
已传入3个参数:设备,uid和权重。并采用不同的字符串格式。这包括将字符串参数作为JSON字符串传递,在UDF中使用JSON.stringify()或仅包含数据而没有标题(“设备”,“ uid”,“权重”)的参数发送。但是所有对ML服务的调用都失败了。
WITH QUERY1 AS (
SELECT DEVICE, UID, WEIGHT,
udf.jsonstringify( concat('{"device": "',try_cast(device as nvarchar(max)), '"}')) jsondevice,
udf.jsonstringify( concat('{"uid": "',try_cast(uid as nvarchar(max)), '"}')) jsonuid,
udf.jsonstringify( concat('{"weight": "',try_cast(weight as nvarchar(max)), '"}')) jsonweight
FROM iothubinput2018aug21 ),
QUERY2 AS (
SELECT IntellistokML2018Aug21(JSONDEVICE, JSONUID, JSONWEIGHT) AS RESULT
FROM QUERY1
)
SELECT *
INTO OUT2BLOB20
FROM QUERY2
大多数错误是: ValueError:int()以10为底的无效文字:'\\“ {weight:9'\ n \ r \ n \ r \ n
ML服务希望这些参数以什么格式传递?
注意:已使用ASA兼容级别1和1.1尝试查询。
答案 0 :(得分:0)
在ASA函数中,您不需要自己为Azure ML构造JSON输入。您只需直接指定事件字段。例如:
QUERY1 AS( 选择结果为IntellistokML2018Aug21(DEVICE,UID,WEIGHT) 来自iothubinput2018aug21 )
选择*
INTO OUT2BLOB20
来自QUERY1
答案 1 :(得分:0)
如Dushyant帖子中所述,您无需为Azure ML构造JSON输入。但是,我注意到您的输入是带有Array的嵌套JSON,因此您需要在第一步中提取字段。
这里有个例子:
WITH QUERY1 AS(
SELECT
GetRecordPropertyValue(GetArrayElement(inputs.input,0),'device') as device,
GetRecordPropertyValue(GetArrayElement(inputs.input,0),'uid') as uid,
GetRecordPropertyValue(GetArrayElement(inputs.input,0),'weight') as weight
FROM iothubinput2018aug21 )
请注意,如果“ Inputs.input”数组中可以包含多个消息,则可以使用CROSS APPLY读取所有消息(在我的示例中,我仅假设有一个)。
有关查询JSON的更多信息,请访问:https://docs.microsoft.com/en-us/azure/stream-analytics/stream-analytics-parsing-json
让我们知道它是否对您有用。
JS(Azure流分析)
答案 2 :(得分:0)
事实证明,ML服务期望使用具有已知Mac ID的设备。如果使用未知的MAC ID传递设备,则Python脚本将失败。这应该更优雅地处理。
现在存在与批处理行有关的错误:
"Error": "- Condition 'The number of events in Azure ML request ID 0 is 28 but the
number of results in the response is 1. These should be equal. The Azure ML model
is expected to score every row in the batch call and return a response for it.'
should not be false in method
'Microsoft.Streaming.CalloutProcessor.dll
!Microsoft.Streaming.Processors.Callout.AzureMLRRS.ResponseParser.Parse'
(Parse at offset 69 in file:line:column <filename unknown>:0:0\r\n)\r\n",
"Message": "An error was encountered while calling the Azure ML web service. An
error occurred when parsing the Azure ML web service response. Please check your
Azure ML web service and data model., - Condition 'The number of events in Azure ML
request ID 0 is 28 but the number of results in the response is 1. These should be
equal. The Azure ML model is expected to score every row in the batch call and
return a response for it.' should not be false in method
'Microsoft.Streaming.CalloutProcessor.dll
!Microsoft.Streaming.Processors.Callout.AzureMLRRS.ResponseParser.Parse' (Parse at
offset 69 in file:line:column <filename unknown>:0:0\r\n)\r\n, :
OutputSourceAlias:query2Callout;",
Type": "CallOutProcessingFailure",
"Correlation ID": "2f87188e-1eda-479c-8e86-e2c4a827c6e7"
我正在研究本文以寻求指导: [使用Azure机器学习功能扩展您的Stream Analytics作业] [1]:https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/stream-analytics/stream-analytics-scale-with-machine-learning-functions.md
答案 3 :(得分:0)
我无法在原始主题中对此添加评论,因此请在此处回复: “ Azure ML中的事件数 请求ID 0为28,但响应中的结果数为1。这些应为 相等”
ASA对Azure ML的调用被建模为标量函数。这意味着每个输入事件都需要恰好生成一个输出。就您而言,似乎您正在为28个输入事件生成一个输出。您可以修改逻辑以为每个输入事件生成输出吗?
答案 4 :(得分:0)
关于JSON格式: {“ Inputs”:{“ input”:[{“ device”:“ 60-c5”,“ uid”:“ 5f422”,“ weight”:“ 9--15”}]},“ GlobalParameters”:{} }
ASA会在调用AML时添加所有额外的标记。您是否可以检查AML网络服务收到的输入?例如,修改您的模型代码以写入blob。
答案 5 :(得分:0)
AML调用应遵循标量语义-每个输入一个输出。