vladmandic / human

Human: AI-powered 3D Face Detection & Rotation Tracking, Face Description & Recognition, Body Pose Tracking, 3D Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction, Gaze Tracking, Gesture Recognition
https://vladmandic.github.io/human/demo/index.html
MIT License
2.38k stars 325 forks source link

Using mobilenet as face detection model #473

Closed SirVizzy closed 2 months ago

SirVizzy commented 5 months ago

Hi.

At the moment I am using FaceAPI with the MobileNetV1 model for face detection in images. I have off-loaded the work to a WebWorker which works fine when WebGL is supported. However, on my phone the tensorflow backend keeps being set to cpu. Which is problematic as it's stupendously slow; I would need some fallback mechanism where opengl => wasm => cpu.

Since FaceAPI wasn't originally designed to be used with a worker, I would like to try Human.

I have tried numerous models to see which fits my use-case best. And I seem to be getting the best results using the MobileNetV1 model (better than Blazeface). So my question is, is it possible to use the MobileNetV1 model instead? Also does this package come with proper tree shaking?

SirVizzy commented 5 months ago

I did find the following in the documentation; https://github.com/vladmandic/human-models. However, I could not find the model I was looking for in there. I am looking for a model that works for both short- and longer range detection which high accuracy and low error rates.

vladmandic commented 5 months ago

did you evaluate face detection model in human as-is? i don't have plan to implement much older mobilenetv1 in human.

SirVizzy commented 5 months ago

Yes. Blazeface isn't cutting it with images with groups of people in varying distances (for either sparse or regular). I do see a mobilefacenet in https://github.com/vladmandic/human-models/tree/main/models which has equal amount of bytes to that model. Is it similar? Do you know the origin?

Edit: Most problematic issue with blazeface that I am encountering is a ton of false detections. In my case I need something with a low error rate as I am using this to not crop out faces out of pictures.

Using the following code I am not seeing any results (code just stops executing after human.detect is called);

import Human from "@vladmandic/human";

export const createDetector = () => {

    const human = createHumanInstance();

    /**
     * @param {ImageData} imageData
     */
    const detectFacesIn = async (imageData) => {
        return human.detect(imageData);
    };

    return {
        detectFacesIn
    };
};

const createHumanInstance = () => {
    return new Human({
        debug:         true,
        backend:       "webgl",
        modelBasePath: `${self.location.origin}/assets/models/face-detection`,
        face: {
            enabled:  true,
            detector: {
                modelPath:   'mobilefacenet.json',
                maxDetected: 100,
            },
            mesh:        {enabled: false},
            attention:   {enabled: false},
            iris:        {enabled: false},
            emotion:     {enabled: false},
            description: {enabled: false},
            antispoof:   {enabled: false},
            liveness:    {enabled: false},
        },
        body:         {enabled: false},
        hand:         {enabled: false},
        object:       {enabled: false},
        segmentation: {enabled: false},
        gesture:      {enabled: false},
        filter:       {enabled: false}
    });
};

Seems like this model isn't used for face detection. Are there no alternatives?

vladmandic commented 2 months ago

Most problematic issue with blazeface that I am encountering is a ton of false detections

did you try changing params? default min-confidence is 0.2 which is really low as assumption is that detected faces would be further filtered out by analysis part. if you're running just detect part, then you need to tweak it to your liking.

if you want to use alternative face detection, see demo/faceid for config syntax. although at this time only blazeface is fully supported.