0

I am trying to use tensorflow.js to predict output from pre-trained object detection model, but I am getting error in model.predict(inputImage) which is

Uncaught (in promise) Error: Input tensor count mismatch,the graph model has 425 placeholders, while there are 1 input tensors.

I am using
- tensorflowjs version - 1.0.1
- tensorflow - 2.0.0-dev20190404

Html "https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"

I am using SSD_Mobilenet_V2 model and downloaded it from 'http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_coco_2018_03_29.tar.gz'

I used this command to convert tf model into web format

tensorflowjs_converter --input_format tf_saved_model ./saved_model ./tfjs_saved_modelSSDMobilenetV2

Getting error in this line of javascript code:

const boxes = await model.predict(processedImage);

The processedImage is tf.tensor3d of shape (300,300,3).

3
  • Could you add more of the error ? Commented Apr 8, 2019 at 16:17
  • Cross-referencing to the GitHub issue that looks like the same thing. Commented Oct 24, 2019 at 5:50
  • Did you get solution? I am facing the same issue. Commented Jan 10, 2020 at 10:52

3 Answers 3

2

This appears to be related to the GitHub issue here - see also the GitHub issue here for background information.

Fortunately, the solution is simple: you just need to manually specify the input and output nodes when you make the call. I tested this with the model here, tensorflowjs 1.2.10.1, and tfjs 1.2.10.

    let outputs = await model.executeAsync(
        { 'image_tensor' : tf.zeros([1, 300, 300, 3]) },
        [ 'detection_boxes','detection_scores','detection_classes','num_detections']);
    tf.print(outputs);

That yields the following without errors:

Tensor
    [[[0, 0, 0, 0],
      [0, 0, 0, 0],
      [0, 0, 0, 0],
      ...,
      [0, 0, 0, 0],
      [0, 0, 0, 0],
      [0, 0, 0, 0]]],Tensor
     [[0, 0, 0, ..., 0, 0, 0],],Tensor
     [[1, 1, 1, ..., 1, 1, 1],],Tensor
    [0]

Good luck!

Sign up to request clarification or add additional context in comments.

7 Comments

Did you get the working solution? Please share if possible!
Yes, the steps in my answer should work - are you running into the same problem? If so, did those steps work for you?
It worked but how can I convert reshape web cam image to (300,300,3) that I don't know. So I am struggling at the moment and there is no clear document about tensorflow.js. Please feel free to correct me.
@Could you please guide me how to resize tensor in Tensorflow.js? SSD takes (300,300,3) as input while image using webcam has different dimensions.
Are you familiar with the Tensorflow.js tutorial doing image classification from the webcam? In that tutorial they just size the webcam capture element to the correct size (224x224 for MobileNet). Otherwise, use tf.browser.fromPixels with any of the allowable inputs. For example, you can draw an Image() on a canvas using resizing and then pass in the Canvas. Also, make sure that if the image needs to be preprocessed that is done too.
|
0

We are having the same error. At the moment we guess:

  • it is related to the fact that the model was initially trained with tensorflow 1.x and tensorflowjs now loads with its converter tensorflow 2.0-alpha.
  • Introspecting the model.json we find a lot of "unused_control_flow_input_" which could relate to input tensor only used for training purposes.

However, we are only guessing and there is no documentation. The interchangeability of the tensorflow platform is so important for any real production deployments but here we are missing really missing many information.

5 Comments

Ever figure this out?
I would check the newest version of TFJS it fixed some of our problems.
I ran into similar problem. Did anyone come up with any solution yet?
Maybe. I'm checking to see if it is the same problem I was looking at on the GitHub issue
@msek: Did you get the working solution? Please share if possible!
0

coco-ssd uses (1, 300, 300, 3) for the shape: https://github.com/tensorflow/tfjs-models/blob/master/coco-ssd/src/index.ts

Maybe that's the problem?

1 Comment

Did you get the working solution? Please share if possible!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.