justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.68k stars 3.71k forks source link

Getting a match with children #448

Closed adviner closed 5 years ago

adviner commented 5 years ago

I'm using the following code to loop through my sample images using the following code:

    const imageFile = 'eric_2.jpg';

   await faceapi.nets.ssdMobilenetv1.loadFromDisk('./models/ssd_mobilenetv1');
   await faceapi.nets.faceLandmark68Net.loadFromDisk('./models/face_landmark_68');
   await faceapi.nets.faceRecognitionNet.loadFromDisk('./models/face_recognition');
   await faceapi.nets.ageGenderNet.loadFromDisk('./models/age_gender_model');

      // This method returns the files in the specified path
   const files = await api.listFiles(`${__dirname}/images/`);
   const image1 = await canvas.loadImage(`./images/${imageFile}`);
   const detection1 = await faceapi.detectSingleFace(image1, new faceapi.SsdMobilenetv1Options()).withFaceLandmarks().withFaceDescriptor();

   for(const file of files){

        const image2 = await canvas.loadImage(`./images/${file}`);
        const detection2 = await faceapi.detectSingleFace(image2, new faceapi.SsdMobilenetv1Options()).withFaceLandmarks().withFaceDescriptor();
        const distance = await faceapi.euclideanDistance(detection1.descriptor, detection2.descriptor);

        var match = '=> not a match';
        if(distance < 0.7)
            match = '=> match';

        console.log(`Euclidean distance from image: ${imageFile} to ${file} is ${distance} ${match}`);
        console.log('');
    }
}

I take it back it seems like I get a match with everyone I have taken using my phone to my image

**Here is the code output of my kids that is saying its a match:

Euclidean distance from image: eric_1.jpg to dj.jpg is 0.4787967301362279 => match Euclidean distance from image: eric_1.jpg to drew.jpg is 0.5003818530582609 => match**

Celebrities I'm testing that does not match:

Euclidean distance from image: eric_1.jpg to brad_pitt.jpg is 0.7968919207835512 => not a match Euclidean distance from image: eric_1.jpg to cindy_crawford.jpg is 0.8775858144569341 => not a match Euclidean distance from image: eric_1.jpg to kaley_cuoco_1.jpg is 0.8474952774223865 => not a match Euclidean distance from image: eric_1.jpg to kaley_cuoco_2.jpg is 0.8581044739989803 => not a match

More pictures of me that matches. Euclidean distance from image: eric_1.jpg to eric_1.jpg is 0 => match Euclidean distance from image: eric_1.jpg to eric_2.jpg is 0.36870495014601334 => match Euclidean distance from image: eric_1.jpg to eric_3.jpg is 0.680211514000396 => match

The images of me and my kids are 3456x4608 72dpi. The images of the celebrities I just downloaded from the web 1435x2154 300dpi. I downloaded the models from the URL https://github.com/justadudewhohacks/face-api.js-models

Am I doing something wrong? This is my first attempt using this API.

Thanks

adviner commented 5 years ago

This can be disregarded. After looking at the landmarks I created I noticed that my pictures were rotated 90degrees. After rotating them back to properly show the right position it gives me the right results now.