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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.