justadudewhohacks / face-api.js

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

Uncaught (in promise) TypeError: d is not a function #894

Open ahmadbadpey opened 1 year ago

ahmadbadpey commented 1 year ago

I'm using your Javascript API to develop a web app that user uploads her/his picture and we want to detect faces in the picture.

this is my HTML codes:

<input type="file" id="user_pic" accept="image/x-png,image/gif,image/jpeg">
<img src="images/250x250.webp" id="preview" alt="">

and following code are what I wrote to face detection:

const MODEL_URL = '../faceapi_models'
Promise.all([
    faceapi.nets.ssdMobilenetv1.loadFromUri(MODEL_URL),
    faceapi.nets.faceRecognitionNet.loadFromUri(MODEL_URL),
    faceapi.nets.faceLandmark68Net.loadFromUri(MODEL_URL),
]).then((val) => {
    console.log(val)
}).catch((err) => {
    console.log('err')
})

const user_pic = document.getElementById('user_pic')
const preview = document.getElementById('preview')

user_pic.addEventListener('change', () => {
    const reader = new FileReader()
    reader.onload = (e) => {
        preview.src = e.target.result
    }
    reader.readAsDataURL(user_pic.files[0]);

    detectFaces(user_pic.files[0])
})

preview.onclick = () => user_pic.click()

async function detectFaces(input) {

    let imgURL = URL.createObjectURL(input)

    const imgElement = new Image()
    imgElement.src = imgURL

    const results = await faceapi.detectAllFaces(imgElement)
        .withFaceLandmarks()
        .withFaceExpressions()
        .then( results => {
            results.forEach(result => {
                const { x, y, width, height } = result.detection.box;
                console.log(x, y, width, height)
                // ctx.strokeRect(x, y, width, height);
            });
        });

}

Now whenever I select an image this error occured:

Uncaught (in promise) TypeError: d is not a function

What is problem?

emranio commented 1 year ago

i'm having the same problem? did you find any fix? @ahmadbadpey

ahmadbadpey commented 1 year ago

I do not remember what I did exactly But I think just commented this lines:

        .withFaceLandmarks()
        .withFaceExpressions()
shrivastavanihal commented 1 week ago

I do not remember what I did exactly But I think just commented this lines:

        .withFaceLandmarks()
        .withFaceExpressions()

After removing withFaceLandmarks(), did it not create any other issues?