.joblib/.pkl file not supported

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 is how im loading it to streamlit.

Anyone knows how can I load it?

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.

I exported my model using joblib as such:

joblib.dump(modelo,'/content/drive/MyDrive/NLP/RFC_Proyecto.joblib')

And then imported it also using joblib:

  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('RFC_Proyecto.joblib')
    else:
        loaded_model = tf.keras.models.load_model(model_options[selected_model])

Am I doing something wrong?

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 created the model using sklearn.ensemble, and vectorized my df using word2vec.

I don’t know any details of your model, but why do you try to load a sklearn model with keras?

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

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