Last active
August 27, 2018 21:46
-
-
Save hawkeye64/aa02cb7ac08ac2e46012ef9dae362410 to your computer and use it in GitHub Desktop.
The "predict" function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Predicts classifications based on passed in image | |
* @param {Object} img The image to use for predictions | |
*/ | |
const predict = (img) => { | |
// white is the better padding color | |
const white = new cv.Vec(255, 255, 255) | |
// resize to model size | |
const theImage = img.resizeToMax(modelData.size, modelData.size).padToSquare(white) | |
// network accepts blobs as input | |
const inputBlob = cv.blobFromImage(theImage) | |
net.setInput(inputBlob) | |
// forward pass input through entire network, will return | |
// classification result as (coco: 1x1xNxM Mat) (inception: 1xN Mat) | |
let outputBlob = net.forward() | |
if (dataFile === 'coco300' || dataFile === 'coco512') { | |
// extract NxM Mat from 1x1xNxM Mat | |
outputBlob = outputBlob.flattenFloat(outputBlob.sizes[2], outputBlob.sizes[3]) | |
// pass original image | |
return extractResultsCoco(outputBlob, img) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment