I'm creating a Firebase hosted webapp based on Google's I/O '17 presentation where Google's AutoML Vision can take a picture of a cloud and tell you what type of cloud it is based on its machine learning training. The code I'm using only allows for one call and I think it's due to the following piece of the code:
// Get only the first prediction response
let data = response[0]['payload'];
predictions[data[0].displayName] = data[0].classification.score;
From what I can tell from Google's Documentation the [0] corresponds to a annotateImageID. The issue with the code passing 0 is that the webapp is unable to get predictions on more than one image.
Below is the whole portion of the code calling for the results to push to the 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();
}
});
});
})