TFJS-object-detection icon indicating copy to clipboard operation
TFJS-object-detection copied to clipboard

[Solved] TensorList shape mismatch: Shapes -1 and 3 must match

Open nirchetrit opened this issue 3 years ago • 9 comments

After exporting the model and testing that it works properly, I've converted it to Tensorflowjs following your steps. I've loaded it to the browser and I can't find the way to let it predict an image,

Here's the code:

const process_input = (image ) => { const tfimg = tf.browser.fromPixels(video_frame).toInt(); const expandedimg = tfimg.transpose([0, 1, 2]).expandDims(); return expandedimg; }; const image = document.getElementById('image'); const preImage = process_input (image); tf.engine().startScope(); model.executeAsync(testImg).then(predictions => { console.log(predictions); tf.engine().endScope(); });

Right after that, I got an error saying:

Unhandled Rejection (Error): TensorList shape mismatch: Shapes -1 and 3 must match

nirchetrit avatar Feb 11 '21 21:02 nirchetrit

I have the same issue

estefaniatc avatar Feb 15 '21 04:02 estefaniatc

I have the same problem

hubblin avatar Feb 15 '21 08:02 hubblin

The problem was with TensorFlowJS 3.0.0 after upgrading to 3.1.0 I can confirm all work well, just when converting the model - do not use the converter wizard as it adds the argument --control_flow_v2=True which causes a different problem.

nirchetrit avatar Feb 21 '21 06:02 nirchetrit

Well noticed, @nirchetrit! Thanks for your contribution

hugozanini avatar Feb 21 '21 11:02 hugozanini

The problem was with TensorFlowJS 3.0.0 after upgrading to 3.1.0 I can confirm all work well, just when converting the model - do not use the converter wizard as it adds the argument --control_flow_v2=True which causes a different problem.

please share a saved_model.pb file with me, thanks

xilanhuaweidapao avatar Feb 25 '21 09:02 xilanhuaweidapao

Hey, please make sure you are running: "@tensorflow/tfjs": "^3.1.0", "@tensorflow/tfjs-converter": "^3.1.0",

As well tfjs-converter 3.1.0 in your python environment..

For the converter use the following command:

tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --signature_name=serving_default \
    --saved_model_tags=serve \
    saved_model \
    web_model

Anyway, this is the issue post

nirchetrit avatar Feb 25 '21 10:02 nirchetrit

Hey, please make sure you are running: "@tensorflow/tfjs": "^3.1.0", "@tensorflow/tfjs-converter": "^3.1.0",

As well tfjs-converter 3.1.0 in your python environment..

For the converter use the following command:

tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --signature_name=serving_default \
    --saved_model_tags=serve \
    saved_model \
    web_model

Anyway, this is the issue post

i just want a saved_model.pb thanks [email protected]

xilanhuaweidapao avatar Feb 25 '21 10:02 xilanhuaweidapao

Hi @nirchetrit , I have encountered the same issue so I followed your solution. To be more specific:

  1. I have created the virtualenv with tensorflowjs-converter 3.1.0
  2. I have cloned the app from @hugozanini repository.
  3. Instead of executing "npm install "I have manually installed tfjs, tfjs-converter, tfjs-node, tfjs-core : all in 3.1.0 version
  4. I also installed tfjs-data and tfjs-layers as they were listed as necessary when I execute " npm list --depth=0" command

Unfortunately I still can't get it working now with different error: " Unhandled Rejection (TypeError): undefined is not a function (near '...scores[0].forEach...') " .

I am training exact same model on the same data as @hugozanini. My version of model is here: https://raw.githubusercontent.com/TrybusRafalJan/TWM_projekt/main/web_model/model.json

I would much appreciate your help.

TrybusRafalJan avatar Apr 21 '21 18:04 TrybusRafalJan

Hi @nirchetrit , I have encountered the same issue so I followed your solution. To be more specific:

  1. I have created the virtualenv with tensorflowjs-converter 3.1.0
  2. I have cloned the app from @hugozanini repository.
  3. Instead of executing "npm install "I have manually installed tfjs, tfjs-converter, tfjs-node, tfjs-core : all in 3.1.0 version
  4. I also installed tfjs-data and tfjs-layers as they were listed as necessary when I execute " npm list --depth=0" command

Unfortunately I still can't get it working now with different error: " Unhandled Rejection (TypeError): undefined is not a function (near '...scores[0].forEach...') " .

I am training exact same model on the same data as @hugozanini. My version of model is here: https://raw.githubusercontent.com/TrybusRafalJan/TWM_projekt/main/web_model/model.json

I would much appreciate your help.

You have you change de index in the boxes, scores and classes variables

Amonsalvek avatar Jul 09 '22 21:07 Amonsalvek