justadudewhohacks / face-api.js

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

Face expression probabilities random on chrome android #278

Open davidstrahm opened 5 years ago

davidstrahm commented 5 years ago

After loading and detecting face from html video element, the probability distribution is correct for a few frames (happy 0.99, sad 0.0000343) etc.

After a few processed frames, the probabilities jump all over the place (see screenshots below).

The same code works fine when using it in chrome on my desktop machine (Nvidia GTX 1060)

Android 8.0.0 Chrome 73.0.3683.90 Samsung Galaxy S7

probabilities

const model = FaceApiFaceDetectorModel.TINY_FACE_DETECTOR;
const modelBaseUrl = '/assets/tfmodels';
const minConfidence = 0.5;
const inputSize = 256;
const scoreThreshold = 0.5;
const minFaceSize = 200;

await loadFaceDetectorModel(model, modelBaseUrl);
await faceapi.loadFaceExpressionModel(modelBaseUrl);

const options = getFaceDetectorOptions(model, minConfidence, inputSize, scoreThreshold, minFaceSize);

const result = await faceapi.detectSingleFace(video, options).withFaceExpressions();

Might this be some kind of overflow?

Edit: I tried it with the sample application (examples-browser) by updating the "video face tracking" example. The result is the same: Works on desktop, random values on mobile

justadudewhohacks commented 5 years ago

That's odd, especially since these are not even valid probabilities anymore. Looks like something is going wrong in tf.softmax here.

davidstrahm commented 5 years ago

Maybe this is related: https://github.com/tensorflow/tfjs/issues/1488, although face-api does not do batch predictions, does it?

The probabilities are correct on newer phones. Do you have any plans to upgrade your tfjs dependency? Might be this is already fixed.

justadudewhohacks commented 5 years ago

The code that you posted does not do batch processing. Did you try to play around with enabling/disabling the specific features as @annxingyuan described in this issue? Does that help?

davidstrahm commented 5 years ago

Yes, I tried all 3 suggestions. The predictions are "better" when setting tf.ENV.set('WEBGL_PACK', false) (no more huge numbers), but still there are negative values and values in the range from -100 to 100.

justadudewhohacks commented 5 years ago

Ok. All I can do for now is upgrade tfjs-core to latest, which I am working on now.

davidstrahm commented 5 years ago

Thank you, I'll let you know in this issue if that helped

justadudewhohacks commented 5 years ago

Ok I will have to postpone the upgrading, since tfjs-core 1.1.2 seems to not come with the platform specific check, which seems to be implemented in the current master. This breaks the unit tests, since the browser tests utilize a wrong fetch function.

davidstrahm commented 5 years ago

Let me know if we can help

davidstrahm commented 5 years ago

Update: seems to work now on chrome mobile 74.0.3729.136