face-api.js: Error: Based on the provided shape, [1,1,16,32], and dtype float32, the tensor should have 512 values but has 93

Hi! I’m having trouble making the library work on production. Everything works perfect locally. Using angular 4. Here is the code:

const detections: Array<any> = await faceapi.detectAllFaces(this.video, new faceapi.TinyFaceDetectorOptions({ inputSize: 128, scoreThreshold: 0.4 }));

ERROR Error: Uncaught (in promise): Error: Based on the provided shape, [1,1,16,32], and dtype float32, the tensor should have 512 values but has 93 Error: Based on the provided shape, [1,1,16,32], and dtype float32, the tensor should have 512 values but has 93 at c (scripts.208b17eda93ff84a86fa.bundle.js:1) at new t (scripts.208b17eda93ff84a86fa.bundle.js:1) at Function.t.make (scripts.208b17eda93ff84a86fa.bundle.js:1) at Ht (scripts.208b17eda93ff84a86fa.bundle.js:1) at o (scripts.208b17eda93ff84a86fa.bundle.js:1) at $a (scripts.208b17eda93ff84a86fa.bundle.js:1) at scripts.208b17eda93ff84a86fa.bundle.js:1 at Array.forEach (<anonymous>) at scripts.208b17eda93ff84a86fa.bundle.js:1 at Array.forEach (<anonymous>) at c (scripts.208b17eda93ff84a86fa.bundle.js:1) at new t (scripts.208b17eda93ff84a86fa.bundle.js:1) at Function.t.make (scripts.208b17eda93ff84a86fa.bundle.js:1) at Ht (scripts.208b17eda93ff84a86fa.bundle.js:1) at o (scripts.208b17eda93ff84a86fa.bundle.js:1) at $a (scripts.208b17eda93ff84a86fa.bundle.js:1) at scripts.208b17eda93ff84a86fa.bundle.js:1 at Array.forEach (<anonymous>) at scripts.208b17eda93ff84a86fa.bundle.js:1 at Array.forEach (<anonymous>) at S (polyfills.b05dc6a29a1cfeb080d6.bundle.js:1) at polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 at a (main.424b2f298a047510607b.bundle.js:1) at t.invoke (polyfills.b05dc6a29a1cfeb080d6.bundle.js:1) at Object.onInvoke (main.424b2f298a047510607b.bundle.js:1) at t.invoke (polyfills.b05dc6a29a1cfeb080d6.bundle.js:1) at e.run (polyfills.b05dc6a29a1cfeb080d6.bundle.js:1) at polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 at t.invokeTask (polyfills.b05dc6a29a1cfeb080d6.bundle.js:1) at Object.onInvokeTask (main.424b2f298a047510607b.bundle.js:1) $ @ main.424b2f298a047510607b.bundle.js:1 t.handleError @ main.424b2f298a047510607b.bundle.js:1 next @ main.424b2f298a047510607b.bundle.js:1 e.object.i @ main.424b2f298a047510607b.bundle.js:1 e.__tryOrUnsub @ main.424b2f298a047510607b.bundle.js:1 e.next @ main.424b2f298a047510607b.bundle.js:1 e._next @ main.424b2f298a047510607b.bundle.js:1 e.next @ main.424b2f298a047510607b.bundle.js:1 e.next @ main.424b2f298a047510607b.bundle.js:1 e.emit @ main.424b2f298a047510607b.bundle.js:1 (anonymous) @ main.424b2f298a047510607b.bundle.js:1 t.invoke @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 e.run @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 t.runOutsideAngular @ main.424b2f298a047510607b.bundle.js:1 onHandleError @ main.424b2f298a047510607b.bundle.js:1 t.handleError @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 e.runGuarded @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 t @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 n.microtaskDrainDone @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1 d @ polyfills.b05dc6a29a1cfeb080d6.bundle.js:1

Also the video is 351x360 pixels

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 23 (1 by maintainers)

Most upvoted comments

It was actually a different problem - the json files managed to get loaded, but the non extension files (e.g. “age_gender_model-shard1”) weren’t. So what I did - I used my downloaded “weights” folder (and not the cdn), and for each model I :

  1. added a fictional “.shard” extension for the non extension file.
  2. opened the corresponding “…_manifest.json” file and changed the “path” property to the new file name including the “.shard” extension.

For example:

  1. /age_gender_model-shard1 renamed to /age_gender_model-shard1.shard
  2. opened age_gender_model-weights_manifest.json, and changed "paths":["age_gender_model-shard1"] to: "paths":["age_gender_model-shard1.shard"]

Pay attention that some manifest.json files have 2 paths

I managed to solve it serving model files from a cdn Use https://gitcdn.xyz/repo/justadudewhohacks/face-api.js/master/weights/ as MODEL_URL

Added .bin file extension to tiny_face_detector tfjs model. Else the file is not being served in production mode.

Changed the file "face_detector_model-shard1" to "tiny_face_detector_model-shard1.bin" and updating the path in detector_model-weights_manifest.json file like below "paths":["tiny_face_detector_model-shard1.bin"]

For me, this problem caused by the uploading process. I’m using filezilla and it’s solved by change the transfer type to binary.

Sorry for commenting on closed issue.

  1. .shard

This solution worked for me. Thanks! But this strange why it needs an extension for production on iOS.

@aryehrein , well it tends to hibernate occasionally. You have to wake it up by pasting the link to weights folder manually on https://gitcdn.xyz/