Forums

Error Read .h5 or .pkl files

Hi,

I'm trying to read some .h5 or .pkl files for chatbot telegram, but I get the following error:

Using this Method:

model = None  # Inisialisasi model

model_file_path = "/home/nutrigood/decision_tree_model.h5"


try:
    with open(model_file_path, 'rb') as model_file:
    model = joblib.load(model_file)
print("Model Loaded!")
except Exception as e:
   print("Error loading the model", e)

I Got Error Below when I run the code:

Error loading the model 0

When as user input, i got error below:

(__init__.py:962 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
  File "/home/nutrigood/.local/lib/python3.10/site-packages/telebot/__init__.py", line 955, in infinity_polling
    self.polling(non_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout,
  File "/home/nutrigood/.local/lib/python3.10/site-packages/telebot/__init__.py", line 1043, in polling
    self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
  File "/home/nutrigood/.local/lib/python3.10/site-packages/telebot/__init__.py", line 1118, in __threaded_polling
    raise e
  File "/home/nutrigood/.local/lib/python3.10/site-packages/telebot/__init__.py", line 1074, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "/home/nutrigood/.local/lib/python3.10/site-packages/telebot/util.py", line 147, in raise_exceptions
    raise self.exception_info
  File "/home/nutrigood/.local/lib/python3.10/site-packages/telebot/util.py", line 90, in run
    task(*args, **kwargs)
  File "/home/nutrigood/nutrigoodfix.py", line 214, in proses_TB
    BBU, TBU, BBTB = model.predict(X_new)[0]
AttributeError: 'NoneType' object has no attribute 'predict'"

The indentation in the try - except clause looks a little bit off, but it looks like the code enters the except branch -- make sure that the file is there and the joblib is able to load it. Regarding the second case, looks like model is None when you try to execute model.predict(X_new)[0].