Skip to content
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

Error: Based on the provided shape, [1,1,16,32], and dtype float32, the tensor should have 512 values but has 93 #131

Closed
psiservices-azubizarreta opened this issue Nov 12, 2018 · 23 comments

Comments

@psiservices-azubizarreta
Copy link

psiservices-azubizarreta commented Nov 12, 2018

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 ()
at scripts.208b17eda93ff84a86fa.bundle.js:1
at Array.forEach ()
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 ()
at scripts.208b17eda93ff84a86fa.bundle.js:1
at Array.forEach ()
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

@justadudewhohacks
Copy link
Owner

Not sure why the code snippet shown above should make any difference in production.

Looking at the error message your issue most likely resides in loading a model. Check that the model files are served correctly in your production environment.

@psiservices-azubizarreta
Copy link
Author

Thanks! That solved it!

@howyea
Copy link

howyea commented Jan 18, 2019

@psiservices-azubizarreta Can you tell me how to solve? I have a same error. Thank you !

@nannan9507
Copy link

@psiservices-azubizarreta Hello ! I hava a same problem as you met, and it's very peremptorily, so。。Can you tell us the way to solve this situation plz ? my very thanks!

@frank505
Copy link

frank505 commented Jun 1, 2019

a bit stuck here too how did you solve it on production?

@atmosuwiryo
Copy link

atmosuwiryo commented Jul 22, 2019

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.

@neel448
Copy link

neel448 commented Aug 7, 2019

@atmosuwiryo this helped!

@avalanche1
Copy link

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

@aryehrein
Copy link

That address seems invalid...

@avalanche1
Copy link

@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/

@aryehrein
Copy link

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

@udit4
Copy link

udit4 commented Dec 19, 2019

@aryehrein It tried that (adding extension in non-extension files) and also changing the name in .json files but it is still not working !!

@udit4
Copy link

udit4 commented Dec 19, 2019

@aryehrein i am getting this => Error: Based on the provided shape, [1,1,128,256], the tensor should have 32768 values but has 12137 (i am using the face_landmark_68_model).

@jairforero
Copy link

Please help
face-api.min.js:1 Uncaught (in promise) Error: Based on the provided shape, [25], the tensor should have 25 values but has 21

@aniskoubaa
Copy link

  1. .shard

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

@maxim1006
Copy link

Maybe it will help somebody:

The error occurred when I started my local server with --spa, when removed it error gone

@nosuko
Copy link

nosuko commented Nov 2, 2020

@aryehrein Changing the file names worked for me! (adding an extension to -shard1 files). Thanks for the tip!! I hope it will help more people.

I would say that in my case I was developing an Ionic 5 (angular) app with face-api. It worked with ionic when testing with "ionic serve" in Chrome browser. It failed (and I need to apply this fix) when I created the app and tested in a real android device.

@LakshmanaBP
Copy link

LakshmanaBP commented Jan 5, 2021

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"]

@rezanos
Copy link

rezanos commented Mar 5, 2021

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"]

Thanks! that's the solution
setting .bin extension makes Content-Type: application/octet-stream for response

@JMHeartley
Copy link

Hello all,
Instead of changing anything about the files I set the MIME type mapping in IIS for "." (no extension) to "application/octet-stream" this make it so it's served as a binary file and my program works just fine now using Blazor. I haven't tested this on IIS express but it might be possible to do the same or similar.

@andrewviva
Copy link

My webserver does not allow paths to be accessed by the browser so I get 404 errors even though the models directory exists. Is there another way that I can load these net jsons?

@JMHeartley
Copy link

My first thought is to host them on some site for free and lots them from there but you might be able to do something else with the updated version of this project => https://github.com/vladmandic/face-api

@Omar52344
Copy link

works for me change extension of the File wihtout extension change for .bin an manifest.json also change in paths
work for me thanks IN ANGULAR

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests