我已经在Google引擎上建立并运行了一个模型,我可以在我的个人计算机上成功地使用。现在,我正在尝试设置Firebase函数来调用我的ML引擎模型。我真的很接近(我想),但我现在正碰壁呢。
ML引擎正在接收我的预测请求,但我无法在回调函数中获得预测结果。
results.predictions总是空的,当我压缩results时,我看到了以下内容:

Stackdriver显示正在成功发送的请求:

您还可以在ML引擎模型仪表板上看到,当我调用云函数时,Last use time 会执行反射。

但是我不明白为什么我不能从ML引擎中得到预测结果。
以下是我作为设置云函数的指南所遵循的内容:https://github.com/GoogleCloudPlatform/ml-functions-helpdesk/blob/master/functions/index.js
这是我目前的云功能,它是通过base64编码的图像数据通过data.imageData传递的,通过复制输出并从我的PC上运行预测请求来验证它是有效的图像编码。
const functions = require('firebase-functions');
const {google} = require('googleapis');
exports.analyzeDetection = functions.https.onCall((data, context) => {
if (data.imageData) {
// Auth
google.auth.getApplicationDefault((err, authClient) => {
if (err) {
console.error("getApplicationDefault err " + err);
return {
prediction: "error"
}
}
//[START ml_engine_auth]
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
// https://developers.google.com/identity/protocols/googlescopes#mlv1
authClient = authClient.createScoped(['https://www.googleapis.com/auth/cloud-platform']);
}
//Create authenticated ml engine client
var ml = google.ml({
version: 'v1',
auth: authClient
});
//[END ml_engine_auth]
// Prediction
ml.projects.predict({
name: `projects/my_project_name/models/my_model_name`,
resource: {
instances: [{"b64": data.imageData}]
}
}, (err, result) => {
// The problem is that result is always null
if (err){
console.error('ERROR ', err);
return {
prediction: "error"
}
}
return {
prediction: "add this after the prediction requests are working"//result.predictions[0].predicted
}
});
});
}
});注意:我混淆了my_project_name和my_model_name,他们并不是这么说的。
我还尝试了多种不同的预测参数变化,例如:
name: 'projects/my_project_name/models/my_model_name',
resource: {
instances: [{"image_bytes": {"b64": data.imageData}, "key": "0"}]
}和
name: 'projects/my_project_name/models/my_model_name',
resource: {
name: 'projects/my_project_name/models/my_model_name',
instances: [{"b64": data.imageData}]
}但他们的表演似乎都一样。
对于为什么我没有从请求中得到预测结果有什么想法吗?谢谢。
发布于 2018-07-01 01:45:12
经过进一步的挖掘、试验、错误等.我已经确定预测结果存储在results.data中而不是results中。例如,我可以在result.data.predictions[0].scores中查看我的分数,在result.data.predictions[0].prediction中查看预测。似乎我最初是被云函数控制台的输出限制所欺骗的,在这个控制台中,data属性被截断,所以我看不到预测结果。
https://stackoverflow.com/questions/51119359
复制相似问题