question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: graph model model.predict throws `avoid the dynamic ops` error

See original GitHub issue

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Pop-os 20.10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Any android device (checked on LG G8x, Oneplus 3)
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version (use command below): ^2.7.0
  • Browser version: NA
  • Tensorflow.js Converter Version: 2.3.0

Describe the current behavior I used tensorflow-js converter to obtain a graph model from keras saved-model. The conversion is successful and also throw any error when loaded using tf.loadGraphModel but when trying to call model.predict it throws following error

Error: This execution contains the node 'StatefulPartitionedCall/model/rnn_1/while/exit/_65', 
which has the dynamic op 'Exit'. Please use model.executeAsync() instead. 
Alternatively, to avoid the dynamic ops, specify the inputs [Identity]

When I try model.executeAsync(), following error occurs

Error: Cannot compute the outputs [Identity] from the provided inputs [the_input]. 
Consider providing the following inputs: []. Alternatively, to avoid the dynamic ops, 
use model.execute() and specify the inputs [Identity]

For model.execute() similar kind of error is thrown. I also tried to specify the outputs arguments for execute and executeAsync but nothing seems to work.

My model consists of following layers:

  • InputLayer
  • Conv1D
  • BatchNormalisation
  • GRU
  • TimeDistributed
  • Softmax - Activation

The tensorflow-js converter readme page mentions that inference is faster for graphModel which I intend to leverage.

Describe the expected behavior model.predict should return a Tensor/TensorArray.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mattsoulanillecommented, Feb 5, 2021

Hi @HarshalRohit. Thanks to @pyu10055, we’ve found a workaround. If you convert the model with --control_flow_v2=true, it should work. I’ve pushed a working example to the private repo, and the exact converter command is in the package.json file. To anyone else reading this, the command is essentially:

tensorflowjs_converter --input_format keras --output_format tfjs_graph_model --control_flow_v2=true model.h5 graphModel/

We’ll continue investigating the cause of this bug, but hopefully that should unblock you for now.

0reactions
playgroundcommented, Jul 10, 2021

@mattsoulanille I tried the work around by adding --control_flow_v2=True

    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --saved_model_tags=serve \
    --control_flow_v2=True \
    --signature_name=serving_default \
    /savedmodel
    /TFConvertModel

I get this error

2021-07-10 16:24:51.705248: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x108c297d0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-07-10 16:24:51.705291: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version

TypeError: Cannot read property 'children' of undefined
    at /object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:3678:33
    at Array.forEach (<anonymous>)
    at /object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:3675:29
    at Array.forEach (<anonymous>)
    at OperationMapper.mapFunction (/object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:3673:18)
    at /object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:3507:56
    at Array.reduce (<anonymous>)
    at OperationMapper.transformGraph (/object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:3506:48)
    at GraphModel.loadSync (/object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:7411:68)
    at GraphModel.<anonymous> (/object-detection/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:7385:52)```
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Keras to make prediction model throws error
Im trying to use Keras model to recommend visits to some content based on his previous visits and other users behaviours.
Read more >
Error: The shape of dict['input_tensor'] provided in model ...
Hi, I converted my saved model to model json using tensorflowjs_converter tensorflowjs_converter \ --input_format=tf_saved_model ...
Read more >
Dealing with the Unknown: Resilience to Prediction Errors
on the model's predictions. This paper presents a systematic approach to quantify the prediction errors of the statistical models of the application.
Read more >
NVIDIA Deep Learning TensorRT Documentation
This NVIDIA TensorRT Developer Guide demonstrates how to use the C++ and Python APIs for implementing the most common deep learning layers.
Read more >
Time Series Prediction with LSTM Recurrent Neural Networks ...
This will give you a point of comparison for new models. Note that you will invert the predictions before calculating error scores to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found