Hi! I’m trying to load my pre-trained layers model into a node.js app. When loading, I got this error:
ValueError: An InputLayer should be passed either a `batchInputShape` or an `inputShape`.
I assumed this was because the InputLayer in my model.json file had the property “batch_shape” instead of “batch_input_shape” and changed it in all relevant layers. I am now getting this error:
ValueError: Corrupted configuration, expected array for nodeData: [object Object]
Here are my questions:
Did manually changing batch_shape to batch_input_shape cause this error, or is this another error? (I am leaning towards the latter, since changing the name of an attribute wouldn’t change the data type?)
What is causing the “Corrupted configuration” error? I don’t see a “nodeData” in my model.json file
Is there documentation for what type every attribute should be in a model.json file? Or, does anyone have an example of a functional model.json file for a layers-model I can check mine against?
Having the same problem here.
A working model saved converted with tfjs.converters.save_keras_model(new_model, ‘js-model’) resulting in model.json and group1-shard1of1.bin.
Loading in nodejs with
const handler = tf.io.fileSystem(MODEL_PATH);
const model = await tf.loadLayersModel(handler);
I apologize for the delayed response and thank you for bringing this issue to our attention, if possible could you please help us with your Github repo or codepen example along with converted TensorFlow.js model (@goblincat I’m getting error while accessing your model files) and complete steps to replicate the same behavior from our end to investigate this issue further from our end ?
Perhaps that would be a good place to start while some of us gets something set up in github.
Btw. I’m on a mac m1 with python 3.11, tensorflow 2.16.1, tensorflow-metal 1.1.0 and tensorflowjs 4.20.0
Has anyone made any progress on this, I just started running into this error yesterday trying to convert a model trained in python 3.11 with tensorflow 2.16.1 to run with tensorflowjs 4.20.0
The steps I have taken are almost identical to goblincat in the original post,
I was going to start looking into this tonight but was curious what others had done for this, I was going to start in the TFJS code to better understand what is expected of the model.json and see if there had been any recent changes in the tensorflowjs python package to the code that saves the json, but I do not want to repeat any work others have done,
Also as stated above, there seems to be a change where batch_input_shape has changed to batch_shape
after manually adjusting the model.json file to rename batch_shape to batch_input_shape and simplify the inbound_nodes array of each layer, I am able to load the modified model.json file using tensorflowjs 4.20.0’s loadLayersModel method.
But isn’t this because you are now using keras 3 by default with 2.16 @Ian_McNaughton ?
You can check the version using python -c 'import keras; print(keras.__version__)' I think.
You need to install keras 2, otherwise it’s saving a keras tensor.
Starting with TensorFlow 2.16, doing pip install tensorflow will install Keras 3. When you have TensorFlow >= 2.16 and Keras 3, then by default from tensorflow import keras (tf.keras) will be Keras 3.