Can't get descriptor of image (save my thesis)
mq61520 opened this issue · 3 comments
The situation is that I want to train the system to recognize some faces, but I don't know if I'm missing something that I can't get the description of the face.....
My code (I use React):
const handleTraining = async () => {
const labels = ['Captain', 'Thor', 'Tony Stark'];
return Promise.all(
labels.map(async label => {
const descriptions = [];
for (let i = 1; i <= 3; i++) {
const img = await faceapi.fetchImage(`/training/${label}/${i}.jpg`);
const detection = await faceapi.detectSingleFace(img).withFaceLandmarks().withFaceDescriptor();
console.log(detection.descriptor);
descriptions.push(detection.descriptor);
}
console.log('Train xong ' + label);
return new faceapi.LabeledFaceDescriptors(label, descriptions);
})
);
}
Here is what I get when console.log(detection.descriptor):
Float32Array(128) [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, …]
It seems that your code successfully detects faces in your images, but the descriptors that it returns are all NaN (Not a Number). This indicates that there may be an issue with the face detection process, or with the way that the descriptors are being calculated.
Here are a few potential reasons why your descriptors might be returning NaN:
Face detection failure: If the face detection algorithm fails to detect a face in an image, it may return a NaN descriptor. To check if this is the case, you can add a conditional statement to check if the detection is null or undefined before trying to access the descriptor.
Incorrect input: The face detection algorithm requires high-quality input images to generate accurate descriptors. If your input images are low-quality, blurry, or contain multiple faces, it can cause the algorithm to fail and return NaN descriptors.
I hope this helps you identify the issue with your code.
It recognizes faces in images. But only the description of the face is NaN
As for the input image, I guarantee it has a high resolution.
So I really don't know what I'm getting wrong?