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?