Saving and Loading Descriptors for future use
See original GitHub issueWith ref https://github.com/justadudewhohacks/face-api.js#face-recognition-by-matching-descriptors
I’ve managed to train the faces and and saving the dataset with JSON.stringify(labelledDescriptors)
to a static JSON.
Is there a way to quickly load this dataset, or do I have to load the raw JSON and reinit the dataset with each new faceapi.LabeledFaceDescriptors(name, descriptors)
?
Is there method such as
const labelledDescriptors = await faceapi.fetchDescriptors('/files/labeledDescriptors.json');
const faceMatcher = new faceapi.FaceMatcher(labelledDescriptors);
Pardon, if I didn’t explain myself well. But the objective is to quickly loaded a saved labeledDescriptors for usage.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Saving and loading image descriptors - python - Stack Overflow
Ok, after much searching I found the answer to my own question. The load and save of descriptors is working fine above.
Read more >How to Save and Load Your Keras Deep Learning Model
In this post, you will look at three examples of saving and loading your model to a file: Save Model to JSON. Save...
Read more >Lesson 19.4 – Saving and loading the player information
There are several different ways you could save data: in a database, a comma-separated value file, an XML file, etc. We're going to...
Read more >GameMaker Studio 2 - Best Saving and Loading Tutorial (2.3 ...
Like the other tutorial I did, only better. A universal approach for when you need to save or load data in GameMaker, using...
Read more >Saving and loading MOs and CI coefficients - BAGEL Manual
This file can be read back to provide a reference for a future calculation. ... Description: This option is only used with load_ref....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
const labeledFaceDescriptors = await loadLabeledImages() var json_str = “{"parent":” + JSON.stringify(labeledFaceDescriptors) + “}” // save the json_str to json file
// Load json file and parse var content = JSON.parse(json_str)
for (var x = 0; x < Object.keys(content.parent).length; x++) { for (var y = 0; y < Object.keys(content.parent[x]._descriptors).length; y++) { var results = Object.values(content.parent[x]._descriptors[y]); content.parent[x]._descriptors[y] = new Float32Array(results); } } const faceMatcher = await createFaceMatcher(content);
function loadLabeledImages() { const labels = [‘Black Widow’, ‘Captain America’, ‘Captain Marvel’, ‘Hawkeye’, ‘Jim Rhodes’, ‘Thor’, ‘Tony Stark’] return Promise.all( labels.map(async label => { const descriptions = [] for (let i = 1; i <= 2; i++) { const img = await faceapi.fetchImage(
https://raw.githubusercontent.com/WebDevSimplified/Face-Recognition-JavaScript/master/labeled_images/${label}/${i}.jpg
) const detections = await faceapi.detectSingleFace(img).withFaceLandmarks().withFaceDescriptor() descriptions.push(detections.descriptor) } return new faceapi.LabeledFaceDescriptors(label, descriptions) }) ) }// Create Face Matcher async function createFaceMatcher(data) { const labeledFaceDescriptors = await Promise.all(data.parent.map(className => { const descriptors = []; for (var i = 0; i < className._descriptors.length; i++) { descriptors.push(className._descriptors[i]); } return new faceapi.LabeledFaceDescriptors(className._label, descriptors); })) return new faceapi.FaceMatcher(labeledFaceDescriptors); }
This is not the bestway but it’s working. Set faceMatcher as global variable then you can call faceMatcher.findBestMatch(newdata) to compare new data with your saved dataset.