allow backend change in demo via url params

pull/97/head
Vladimir Mandic 2021-09-30 13:43:15 -04:00
parent c7b2c65c97
commit fcbfc8589a
3 changed files with 20 additions and 19 deletions

View File

@ -9,12 +9,13 @@
## Changelog ## Changelog
### **HEAD -> master** 2021/09/29 mandic00@live.com
- fix face matcher
### **1.5.4** 2021/09/29 mandic00@live.com ### **1.5.4** 2021/09/29 mandic00@live.com
### **origin/master** 2021/09/18 mandic00@live.com
### **1.5.3** 2021/09/16 mandic00@live.com ### **1.5.3** 2021/09/16 mandic00@live.com
- simplify tfjs imports - simplify tfjs imports

View File

@ -9,12 +9,7 @@ const maxResults = 10; // maximum number of results to return
const samples = ['sample1.jpg', 'sample2.jpg', 'sample3.jpg', 'sample4.jpg', 'sample5.jpg', 'sample6.jpg']; // sample images to be loaded using http const samples = ['sample1.jpg', 'sample2.jpg', 'sample3.jpg', 'sample4.jpg', 'sample5.jpg', 'sample6.jpg']; // sample images to be loaded using http
// helper function to pretty-print json object to string // helper function to pretty-print json object to string
function str(json) { const str = (json) => (json ? JSON.stringify(json).replace(/{|}|"|\[|\]/g, '').replace(/,/g, ', ') : '');
let text = '<font color="lightblue">';
text += json ? JSON.stringify(json).replace(/{|}|"|\[|\]/g, '').replace(/,/g, ', ') : '';
text += '</font>';
return text;
}
// helper function to print strings to html document as a log // helper function to print strings to html document as a log
function log(...txt) { function log(...txt) {
@ -110,12 +105,17 @@ async function main() {
// initialize tfjs // initialize tfjs
log('FaceAPI Test'); log('FaceAPI Test');
// if you want to use wasm backend location for wasm binaries must be specified const params = new URLSearchParams(location.search);
// await faceapi.tf.setWasmPaths('../node_modules/@tensorflow/tfjs-backend-wasm/dist/'); log('url options:', params.toString());
// await faceapi.tf.setBackend('wasm'); if (params.has('backend')) {
const backend = params.get('backend');
await faceapi.tf.setWasmPaths('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.9.0/dist/');
log('overriding backend:', backend);
await faceapi.tf.setBackend(backend);
} else {
// default is webgl backend // default is webgl backend
await faceapi.tf.setBackend('webgl'); await faceapi.tf.setBackend('webgl');
}
await faceapi.tf.enableProdMode(); await faceapi.tf.enableProdMode();
await faceapi.tf.ENV.set('DEBUG', false); await faceapi.tf.ENV.set('DEBUG', false);
@ -163,7 +163,7 @@ async function main() {
.withFaceDescriptors() .withFaceDescriptors()
.withAgeAndGender(); .withAgeAndGender();
// print results to screen // print results to screen
print('TinyFace Detector', img, dataTinyYolo); print('TinyFace:', img, dataTinyYolo);
// actual model execution // actual model execution
const dataSSDMobileNet = await faceapi const dataSSDMobileNet = await faceapi
.detectAllFaces(canvas, optionsSSDMobileNet) .detectAllFaces(canvas, optionsSSDMobileNet)
@ -172,7 +172,7 @@ async function main() {
.withFaceDescriptors() .withFaceDescriptors()
.withAgeAndGender(); .withAgeAndGender();
// print results to screen // print results to screen
print('SSD MobileNet', img, dataSSDMobileNet); print('SSDMobileNet:', img, dataSSDMobileNet);
} catch (err) { } catch (err) {
log(`Image: ${img} Error during processing ${str(err)}`); log(`Image: ${img} Error during processing ${str(err)}`);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

View File

@ -52,7 +52,7 @@
"@tensorflow/tfjs-layers": "^3.9.0", "@tensorflow/tfjs-layers": "^3.9.0",
"@tensorflow/tfjs-node": "^3.9.0", "@tensorflow/tfjs-node": "^3.9.0",
"@tensorflow/tfjs-node-gpu": "^3.9.0", "@tensorflow/tfjs-node-gpu": "^3.9.0",
"@types/node": "^16.10.1", "@types/node": "^16.10.2",
"@typescript-eslint/eslint-plugin": "^4.32.0", "@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0", "@typescript-eslint/parser": "^4.32.0",
"@vladmandic/build": "^0.5.3", "@vladmandic/build": "^0.5.3",
@ -70,7 +70,7 @@
"node-fetch": "^3.0.0", "node-fetch": "^3.0.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"seedrandom": "^3.0.5", "seedrandom": "^3.0.5",
"simple-git": "^2.45.1", "simple-git": "^2.46.0",
"tslib": "^2.3.1", "tslib": "^2.3.1",
"typedoc": "^0.22.4", "typedoc": "^0.22.4",
"typescript": "4.4.3" "typescript": "4.4.3"