0

I want to use my deep learning CNN algorithm in a web application and I converted my tensorflow model, emotion_model.h5 to a tensorflow.js model using this command in the terminal

tensorflowjs_converter --input_format keras models/emotion_model.h5 models/tfjs_model However, when I use the tfjs_model in my web app to classify emotions, I am getting the following error on my console:

'Uncaught (in promise) Error: An InputLayer should be passed either a batchInputShape or an inputShape'

Note that I have a clearly defined input_shape parameter during the training of the model and my tensorflow model is working pretty well. Heres a summary of my model layers.

emotion_model = tf.keras.Sequential()

emotion_model.add(tf.keras.layers.Input(shape=(48, 48, 1)))
emotion_model.add(tf.keras.layers.Conv2D(32, kernel_size=(3,3), activation = 'relu'))
emotion_model.add(tf.keras.layers.Conv2D(64, kernel_size=(3,3), activation = 'relu'))
emotion_model.add(tf.keras.layers.MaxPooling2D(pool_size=(2,2)))
emotion_model.add(tf.keras.layers.Dropout(0.25))

emotion_model.add(tf.keras.layers.Conv2D(128, kernel_size=(3,3), activation = 'relu'))
emotion_model.add(tf.keras.layers.MaxPooling2D(pool_size=(2,2)))
emotion_model.add(tf.keras.layers.Conv2D(128, kernel_size=(3,3), activation = 'relu'))
emotion_model.add(tf.keras.layers.MaxPooling2D(pool_size=(2,2)))
emotion_model.add(tf.keras.layers.Dropout(0.25))

emotion_model.add(tf.keras.layers.Flatten())
emotion_model.add(tf.keras.layers.Dense(1024, activation='relu'))
emotion_model.add(tf.keras.layers.Dropout(0.5))
emotion_model.add(tf.keras.layers.Dense(7, activation='relu'))

emotion_model.compile(loss='categorical_crossentropy', optimizer= keras.optimizers.Adam(learning_rate= 0.0001, weight_decay=1e-6), metrics=['accuracy'])

I am using tensorflow==16.0.2 currently. I found similar queries on the internet and their errors were resolved after switching to an older version of tensorflow (tensorflow==15.0.1). I tried uninstalling tensorflow 16.0.2 and installed tensorflow 15.0.1 but my query still isn't resolved. I don't want to train my entire model in tensorflow.js. What can I do to resolve this error?

2
  • Hi@snoopy_doo,The error you're encountering, "An InputLayer should be passed either a batchInputShape or an inputShape", typically occurs when TensorFlow.js encounters issues with the model's input configuration. This issue can arise due to various reasons related to how the model was exported or how it's being used in the web application.Ensure that the model conversion from TensorFlow to TensorFlow.js was done correctly. Sometimes, the issue can stem from a problem during conversion. tensorflowjs_converter --input_format keras models/emotion_model.h5 models/tfjs_model Commented Aug 6, 2024 at 13:24
  • Ensure you are using a compatible version of the TensorFlow.js converter. You can check and upgrade the TensorFlow.js converter pip install --upgrade tensorflowjs Make sure the Input layer in your Keras model has a defined shape. Commented Aug 6, 2024 at 13:27

0

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.