1

I followed the steps in this tutorial to convert a trained TensorFlow model generated using Python. Now I want to use that to re-create the model in TensorFlow JS. I passed the path for model.js like this:

const model = tf.loadLayersModel(pathToModelsDotJSON).then(() => {
    // Do stuff
})

I'm using Vue.js and when I run the code it throws this error:

Uncaught (in promise) Error: The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.
    at new t (tf-layers.esm.js?271e:17)
    at t.add (tf-layers.esm.js?271e:17)
    at t.fromConfig (tf-layers.esm.js?271e:17)
    at deserializeKerasObject (tf-layers.esm.js?271e:17)
    at deserialize (tf-layers.esm.js?271e:17)
    at eval (tf-layers.esm.js?271e:17)
    at eval (tf-layers.esm.js?271e:17)
    at Object.eval [as next] (tf-layers.esm.js?271e:17)
    at o (tf-layers.esm.js?271e:17)

My question is: Why is this happening? And how to solve it?

4
  • 1
    The error says it all; you need to add batchInputShape to your first model. It might not be necessary in Python but in Js it is Commented Jul 14, 2019 at 15:13
  • @edkeveked And how do I pass it? Should I pass it in the same call to loadLayersModel()? Commented Jul 14, 2019 at 15:15
  • 1
    You have to pass it in your python code when you define the model Commented Jul 14, 2019 at 15:18
  • @edkeveked Please post this as an answer so I can accept it. Commented Jul 14, 2019 at 20:09

1 Answer 1

1

1 - You're using the wrong function modelFromJSON to import the model. According to the tutorial, here is the function to use: loadLayersModel.

2-

The first layer in a Sequential model must get an inputShape or batchInputShape argument

You need to add batchInputShape or InputShape to the model defined in Python

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

Comments

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.