pull/186/head
Vladimir Mandic 2022-12-04 13:23:41 -05:00
parent fba823ba50
commit e8301c5277
1 changed files with 5 additions and 2 deletions

View File

@ -27,7 +27,7 @@ async function readImage(imageFile) {
} }
async function main() { async function main() {
wasm.setWasmPaths('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm/dist/'); wasm.setWasmPaths('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm/dist/', true);
await tf.setBackend('wasm'); await tf.setBackend('wasm');
await tf.ready(); await tf.ready();
console.log(`Version: FaceAPI ${faceapi.version} TensorFlow/JS ${tf.version_core} Backend: ${faceapi.tf.getBackend()}`); // eslint-disable-line no-console console.log(`Version: FaceAPI ${faceapi.version} TensorFlow/JS ${tf.version_core} Backend: ${faceapi.tf.getBackend()}`); // eslint-disable-line no-console
@ -38,13 +38,16 @@ async function main() {
await faceapi.nets.faceExpressionNet.loadFromDisk('model'); await faceapi.nets.faceExpressionNet.loadFromDisk('model');
const options = new faceapi.SsdMobilenetv1Options({ minConfidence: 0.1, maxResults: 10 }); // set model options const options = new faceapi.SsdMobilenetv1Options({ minConfidence: 0.1, maxResults: 10 }); // set model options
const tensor = await readImage('demo/sample1.jpg'); const tensor = await readImage('demo/sample1.jpg');
const t0 = performance.now();
const result = await faceapi.detectAllFaces(tensor, options) // run detection const result = await faceapi.detectAllFaces(tensor, options) // run detection
.withFaceLandmarks() .withFaceLandmarks()
.withFaceExpressions() .withFaceExpressions()
.withFaceDescriptors() .withFaceDescriptors()
.withAgeAndGender(); .withAgeAndGender();
tf.dispose(tensor); // dispose tensors to avoid memory leaks tf.dispose(tensor); // dispose tensors to avoid memory leaks
console.log({ result }); // eslint-disable-line no-console const t1 = performance.now();
console.log('time', t1 - t0); // eslint-disable-line no-console
console.log(result); // eslint-disable-line no-console
} }
main(); main();