-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solved: face-api is not compatible with tfjs 2.x or tfjs 3.x #633
Comments
True that!
|
Is there any solution/work-around for this? |
same here, unable to upgrade to 2.0.1 version |
I have same issues like @igorescobar |
Check to see if you have a |
Can you elaborate on that? IMO, loading any specific version of TFJS is not a problem, but if TFJS 2.0 is loaded Face-API will not work since TFJS 2.0 obsoleted some functions - primarily batchNormalization(). And that is a dependency inside models, so models need to be recompiled, it's not just a library code issue. |
Sometimes NPM is stupid; so what happens is you have this: [YourProject] So when faceapi loads tensorflow it loads the v1.0 library from its node_modules; which then when it attempts to load tsflow-node; it gets the v2.0 from the root @tensorflow 2.0 version. Of course v1 doesn't work with v2 and you get that nice cryptic error message. If you NUKE/DELETE the [node_modules] under the faceapi.js folder; then when faceapi.js goes to load tensorflow it will load the 2.0 version from the root node_modules, and that 2.0 will load the tsflow-node which is also 2.0 and everything will work. |
As I said, the issue is not forcing load of TFJS 2.0 - even if you do that, the models used by face-api.js rely on batchNormalization() function that was deprecated and removed in TFJS 2.0 - see: tensorflow/tfjs#3238 and tensorflow/tfjs#3232 Anyhow, I've tried your method (and few others)...
As expected, it doesn't load TFJS at all, it just fails on first usage of any method since instance is undefined.
Result is the same as in first case.
This will do a recompile which may fail due to missing system dependencies, in which case install them manually. E.g.:
Then force package update and do a full rebuild
Fails, so it's not just models that need work
|
Ok, I dug a bit deeper...
So if you're ok using tinyFaceDetector, TFJS 2.0+ works just fine. |
FYI, I've forked face-api.js, updated it for tfjs 2.0, cleaned up obsolete code and modernized build process. |
@vladmandic - You should drop a PR so that this can get fixed... :D |
@NathanaelA I'd be happy to write a PR for minor code changes and update dependencies, but it's really up to the author to clean up models - as it is, there is code for 4 different models and only 1 is working - removing that much code is not something that should be done in a PR. |
I find the accuracy of the I hope this gets fixed soon. |
@focux I agree that ssdMobilenetv1 is generally a bit better than tinyFaceDetector and I wish author retrains model to be compatible with tfjs@2.0+ although not sure how much can be done since mobilenet v1 is a really old model. Ideally, it should be trained with either ssd & mobilenet v2 (that would be simplest as it's very close to existing model) or a newer & better alternative. i've noticed some work has been done in a separate branch https://github.com/justadudewhohacks/face-api.js/tree/face_detection_save, but there are no weights and it hasn't been updated in 3 months. btw, if you really need ssdMobilenetv1, use latest tfjs@1.7.4, not 1.7.0 as there are more than few bugfixes and v1.7.4 is final version in 1.x branch. i'll reopen this issue so it can be monitored... |
One more note, ssd_mobilenetv1 model actually comes from a diferent project, https://github.com/yeephycho/tensorflow-face-detection. > summarize_graph \
--in_graph="./frozen_inference_graph_face.pb" \
--print_structure=false
Found 4 possible outputs: (name=detection_boxes, op=Identity) (name=detection_scores, op=Identity) (name=detection_classes, op=Identity) (name=num_detections, op=Identity)
> tensorflowjs_converter \
--input_format tf_frozen_model \
--output_format tfjs_graph_model \
--skip_op_check \
--strip_debug_ops=True \
--quantize_uint16 \
--weight_shard_size_bytes 4194304 \
--output_node_names detection_boxes,detection_scores,num_detections \
./frozen_inference_graph_face.pb \
./converted/ but...face-api.js model-weights list to iterate and load weights, not full model.json. As it is, tinyFaceDetector works as-is and ssdMobilenetv1 can probably be made to work. Other models are obsolete. |
Done! I've just pushed updated package to https://www.npmjs.com/package/@vladmandic/face-api Model: {name: "FaceAPI SSD/MobileNet v1", modelPath: "models/faceapi/", exec: "ssd", score: 0.3, topK: 1, size: 416 },
Result: {
age: 21.586017608642578
expressions: FaceExpressions {...}
gender: "female"
genderProbability: 0.960713230073452
alignedRect: FaceDetection {...}
descriptor: Float32Array(128) [...]
detection: FaceDetection {...}
landmarks: FaceLandmarks68 {...}
}
{ name: 'FaceAPI TinyYoloDetector', modelPath: 'models/faceapi/', exec: 'yolo', score: 0.3, topK: 1, size: 416 },
Result: {
age: 24.492658615112305
expressions: FaceExpressions {...}
gender: "female"
genderProbability: 0.964848417788744
alignedRect: FaceDetection {...}
descriptor: Float32Array(128) [...]
detection: FaceDetection {...}
landmarks: FaceLandmarks68 {...}
} |
Wow! That's awesome, great work @vladmandic, I will definitely use your package. Thank you. |
Awesome work @vladmandic thank you for sharing! Can I buy you a beer/do you have a tip jar anywhere? :D (and @justadudewhohacks too if you're still around 😃 ) |
no tip jar, just having fun - enjoy! |
Now that TFJS 2.0 has been released, are there any plans to update face-api models to be compatible with it?
Currently it fails due to batchNormalization being obsoleted in tfjs 2.0.
I'm using tfjs with multiple models on the same image to classify/detect all different types of objects (not just faces) and since concurrently loading multiple different versions of tfjs is not possible thus I cannot upgrade entire project because of a face-api dependency on tfjs 1.x.
The text was updated successfully, but these errors were encountered: