我正在基于Google I / O '17演示文稿创建一个Firebase托管的Web应用程序,其中Google的AutoML Vision可以拍摄云的图片,并根据其机器学习训练告诉您它是哪种云类型。我正在使用的代码只允许一个调用,我认为这是由于以下代码段造成的:
// Get only the first prediction response
let data = response[0]['payload'];
predictions[data[0].displayName] = data[0].classification.score;
从Google文档中可以看出,[0]对应于annotateImageID。代码传递0的问题是,Web应用程序无法对多个图像进行预测。
下面是代码的整个部分,要求将结果推送到webapp:
exports.callCustomModel = functions.storage.object().onFinalize(event => {
const file = gcsClient.bucket(event.bucket).file(event.name);
let destination = '/tmp/' + event.name.replace(/\s/g, '');
return file.download({destination: destination})
.then(() => {
if(sizeOf(destination).width > 600) {
console.log('scaling image down...');
return resizeImg(destination);
} else {
return destination;
}
})
.then(() => {
let bitmap = fs.readFileSync(destination);
let data = new Buffer(bitmap).toString('base64');
return callAutoMLAPI(data);
})
.then((response) => {
let predictions = {};
// Get only the first prediction response
let data = response[0]['payload'];
predictions[data[0].displayName] = data[0].classification.score;
if (Object.keys(predictions).length === 0) {
predictions = {"predictionErr": "No high confidence predictions found"};
}
return db.collection('images').doc(event.name).set(predictions);
})
.then(() => {
// Delete tmp image file to clean up resources
return new Promise((resolve, reject) => {
fs.unlinkSync(destination, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
})
答案 0 :(得分:0)
response.payload
的所有预测都超出阈值集。