Error when deploying my app

Hello,
I want to deploy my Car Price Predicition App on the Streamlit Cloud, but everytime I try to deploy it I get the following error message: ValueError: Layer ‘dense’ expected 2 variables, but received 0 variables during loading. Expected: [‘dense/kernel:0’, ‘dense/bias:0’]
When i deploy my app on my local machine everything works fine. I tried every solution I could find on in the internet but none of this works: redeploying the app several times, changing the requirement.txt, uninstall and reinstall anaconda, etc.
It seems like it has something to do with my keras model, becuase if I exclude the keras model the app will deploy and everythign works fine. My model structure is the following:
nn_model = keras.Sequential()

nn_model.add(keras.layers.Input(shape=(data_fitting.x_train.shape[1]),))

nn_model.add(keras.layers.Dense(units=200, activation=‘relu’, kernel_initializer=“normal”))

nn_model.add(keras.layers.Dropout(rate=0.15))

nn_model.add(keras.layers.Dense(units=100, activation=‘relu’, kernel_initializer=“normal”))

nn_model.add(keras.layers.Dropout(rate=0.15))

nn_model.add(keras.layers.Dense(units=10, activation=‘relu’, kernel_initializer=“normal”))

nn_model.add(keras.layers.Dense(units=1))

callback = keras.callbacks.EarlyStopping(monitor=‘val_mae’, patience=10, verbose=1, min_delta=4, mode=“min”)

opt = keras.optimizers.Adam(learning_rate=0.0001)

nn_model.compile(loss=keras.losses.MeanSquaredError(), optimizer=opt, metrics=[“mae”])

history = nn_model.fit(data_fitting.x_train, data_fitting.y_train, epochs=100, validation_split=0.25, callbacks= [callback])

I hope someone can help me. Here is the link to my Git Repo if you want to take a look at my entire code: GitHub - Konwoh/car_price_prediciton

Hi @Konwoh

There seems to be a similar forum post to the error message you’re getting:

Here’s the post:

Alternatively, instead of running the NN model on the cloud, owing to limited resources for communal use, perhaps you could try pre-training the NN model and saving it to file, then loading the model in the app.

Hope this helps.

I saw the similar forum post as well but it doesnt provide a real solution for me. I also pretrained the NN model and load it in my file with model.load(…) like that: loaded_model_nn = keras.models.load_model(“models/nn_model.keras”) but it still wont work. Do you have any other suggestions ? I mean I dont understand why it is working on my local machine but not on the streamlit Cloud.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.