Load model pre-trained with joblib

I’m trying to load a neural network model in my streamlit app, but it appears the error:

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/dry_forest_fire/interface.py", line 20, in <module>
    rede_neural = joblib.load('Models/rede_neural')
  File "/home/appuser/venv/lib/python3.9/site-packages/joblib/numpy_pickle.py", line 587, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "/home/appuser/venv/lib/python3.9/site-packages/joblib/numpy_pickle.py", line 506, in _unpickle
    obj = unpickler.load()
  File "/usr/local/lib/python3.9/pickle.py", line 1212, in load
    dispatch[key[0]](self)
  File "/usr/local/lib/python3.9/pickle.py", line 1589, in load_reduce
    stack[-1] = func(*args)
  File "/home/appuser/venv/lib/python3.9/site-packages/keras/saving/pickle_utils.py", line 40, in deserialize_model_from_bytecode
    with tarfile.open(fileobj=b, mode="r") as archive:
  File "/usr/local/lib/python3.9/tarfile.py", line 1625, in open
    raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully

The other model which I just used random forest loads ok (I also verified the path). I’m trying to load the neural network like this:

import base64
import streamlit as st
import plotly.express as px
import pandas as pd
import numpy as np
import joblib
from sklearn.preprocessing import StandardScaler

neural_network= joblib.load('Models/rede_neural') #Not ok
floresta_aleatoria = joblib.load('Models/floresta_aleatoria') #Load ok


------- Requirements.txt -------
joblib==1.1.1
numpy==1.19.4
pandas==1.4.4
plotly==5.13.1
scikit_learn==1.2.1
streamlit==1.19.0
typing-extensions==3.10.0.0
tensorflow>=2.6.3
tensorflow-cpu>=2.6.3

Can anyone help me about this? Ps.: the local script is running normal

Hi @victoresende19! :wave:

Good to see you back on our forums! :blush:

While this is difficult to diagnose as I haven’t got the full code, here are a few things you may want to double-check:

  1. Verify the file path: Double-check that the path Models/rede_neural is correct and that the file exists in the specified location.

  2. Check file permissions: Ensure that the file has appropriate read permissions for the user running the Streamlit app. You can check and adjust the permissions using the ‘ls -l’ command in a terminal.

  3. Confirm that the version of Keras used to save the model is compatible with the version installed in your environment.

Let us know how it goes.

Best wishes,
Charly

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