I’m working on a proyect with an exported machine learning model, as a .joblib. However, when I import it to streamlit and run my app (locally), y get the following error:
ValueError: File format not supported: filepath=Project.joblib. Keras 3 only supports V3 .keras files and legacy H5 format files (.h5 extension). Note that the legacy SavedModel format is not supported by load_model() in Keras 3. In order to reload a TensorFlow SavedModel as an inference-only layer in Keras 3, use keras.layers.TFSMLayer(Project.joblib, call_endpoint='serving_default') (note that your call_endpoint might have a different name).
This happens even if I import a .pkl file with my model.
model_options = {'FNN': 'ProyectoFnn.h5', 'CNN': 'proyectoCnn.h5', 'Random Forest': 'RFC_Proyecto.joblib'}
selected_model = st.selectbox('🤖 Choose the model to use', list(model_options.keys()))
loaded_model = tf.keras.models.load_model(model_options[selected_model])
if selected_model == 'Random Forest':
loaded_model = joblib.load('Project.joblib')
This has nothing to do with streamlit at all.
When importing a ML model, you should use the same ML framework with which the ML model was created and exported.
Afaik joblib is just a pickle wrapper.
The question is how and with which ML framework was this model created?
And i have some doubts that keras can load random forest models…
I managed to fix the issue. As you mentioned, I forgot to delete the keras loading before my if:
model_options = {'FNN': 'ProyectoFnn.h5', 'CNN': 'proyectoCnn.h5', 'Random Forest': 'RFC_Proyecto.joblib'}
selected_model = st.selectbox('🤖 Choose the model to use', list(model_options.keys()))
if selected_model == 'Random Forest':
loaded_model = joblib.load('RFC_Proyecto.joblib')
else:
loaded_model = tf.keras.models.load_model(model_options[selected_model])```
Then, after that, I just needed to upgrade my scikit-learn library