Skip to content

Instantly share code, notes, and snippets.

@EsteveSegura
Created October 21, 2019 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EsteveSegura/5496a0d21df8fb4691cfeabe2f441294 to your computer and use it in GitHub Desktop.
Save EsteveSegura/5496a0d21df8fb4691cfeabe2f441294 to your computer and use it in GitHub Desktop.
detect food js
const spawn = require('child_process').spawn;
//create friendly js prediction
function decodePrediction(str){
let decode = str.split('-');
return {
"label" : decode[0],
"percentage" : Math.trunc(decode[1])
}
}
//call to vggModel from.py
async function getPrediction(path){
return new Promise((resolve,reject)=>{
const ls = spawn('python', ['vggModel.py', path]);
ls.stdout.on('data', (data) => {
let pred = decodePrediction(data.toString())
resolve(pred)
});
ls.on('close', function (code) {
if(code == 1){
reject('cant_process');
}
});
})
}
module.exports = { getPrediction }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment