justadudewhohacks / face-api.js

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

TinyYolov2 - load model before inference #618

Open swapanil opened 4 years ago

swapanil commented 4 years ago

I am getting this error in production build in React Js and working fine when use npm start.

import * as faceapi from 'face-api.js'

export async function loadModels() {
    const MODEL_URL = process.env.PUBLIC_URL + '/models'
    await faceapi.loadTinyFaceDetectorModel(MODEL_URL)
    await faceapi.loadFaceLandmarkTinyModel(MODEL_URL)
    await faceapi.loadFaceRecognitionModel(MODEL_URL)
}

export async function getFullFaceDescription(blob, inputSize = 512) {
    const scoreThreshold = 0.5
    const OPTION = new faceapi.TinyFaceDetectorOptions({
        inputSize,
        scoreThreshold
    })
    const useTinyModel = true
    const img = await faceapi.fetchImage(blob)
    const fullDesc = await faceapi
        .detectAllFaces(img, OPTION)
        .withFaceLandmarks(useTinyModel)
        .withFaceDescriptors()
}

Please help me on this.

flatsiedatsie commented 4 years ago

I saw the same error in a situation where I wasn't even using the Yolo model, which was confusing.

In the end it was because I had made a coding error, and the models I did want to use weren't actually loaded. Perhaps there is something in the FaceApiJs code where it throws a wrong error for a missing model, and ends up outputting the last name in the list of nets.

buraksekili commented 4 years ago

Hi @swapanil , I am faced with same issue. We have same code block. Have you solve your problem?

buraksekili commented 4 years ago

Hey @swapanil , FYI, I solved my problem. I couldn't load models correctly. Can u check your models location? It should be under the public folder as follows; public/models

amit0shakya commented 4 years ago

I made it sure my all models are loading correctly infact my TinyYolov2 json and shard file loading correctly but still it showing me same issue, I replace it with SsdMobilenetv1Options it is working for now. I think this should be a bug.

RezaRahmati commented 4 years ago

I added this and issue resolved

faceapi.nets.tinyFaceDetector.loadFromUri(this.MODEL_URL),

Abi-Seth commented 3 years ago

This is probably due to failure to load the models you can try loading them like this instead load from url export async function loadModels() { const MODEL_URL = process.env.PUBLIC_URL + '/models' await faceapi.nets.loadTinyFaceDetectorModel.loadFromUri(MODEL_URL) await faceapi.nets.loadFaceLandmarkTinyModel.loadFromUri(MODEL_URL) await faceapi.nets.loadFaceRecognitionModel.loadFromUri(MODEL_URL) }

you can also load them from the disk

await faceapi.nets.loadTinyFaceDetectorModel.loadFromDisk('./models')

st-kam commented 1 year ago

יש לי שגיאה דומה await faceapi.nets.tinyYolov2.loadFromUri('./model'); await faceapi.nets.tinyFaceDetector.loadFromUri('./model'); await faceapi.nets.faceLandmark68Net.loadFromUri('./model'); await faceapi.nets.faceRecognitionNet.loadFromUri('./model'); הוא בכלל לא מצליח להטען וכשאני מנסה להטעין מהאינטרנט עושה לי שגיאה await faceapi.nets.tinyYolov2.loadFromUri('https://example.com/models/tiny_yolov2_model'); await faceapi.nets.tinyFaceDetector.loadFromUri('https://example.com/models/tiny_yolov2_model'); await faceapi.nets.faceLandmark68Net.loadFromUri('https://example.com/models/tiny_yolov2_model'); await faceapi.nets.faceRecognitionNet.loadFromUri('https://example.com/models/tiny_yolov2_model'); אשמח לתשובה דחוף אני הרבה זמן עם זה

Bahriddin-Boboyev commented 5 months ago

I had the same problem. I fixed the problem. here. I used this method and it worked for me :)