7

I am running into this error , i can't unpickle a file on my jupyter notebook:

import os 
import pickle
import joblib
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
filename = open("loan_model3.pkl", "rb")
mdl = pickle.load(filename)
mdl.close()

and it always shows the below error message , even tho i'vce upgraded all my libraries

Error Message:

FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ram://89506590-ec42-44a9-b67c-3ee4cc8e884e/variables/variables You may be trying to load on a different device from the computational device. Consider setting the experimental_io_deviceoption intf.saved_model.LoadOptions to the io_device such as '/job:localhost'.

I tried to upgrade my libraries but still didn't work.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
abdalla mahgoub
  • 71
  • 1
  • 1
  • 5

4 Answers4

5

I got the same error too when I was trying to store my Sequential model in .pkl file, since Sequential model is a TensorFlow Keras model so we have to store it in .h5 file and Keras saves models in this format as it can easily store the weights and model configuration in a single file.

Code:

   from keras.models import load_model
   model.save('model.h5')
   model_final = load_model('model.h5')
Barnana Khan
  • 51
  • 1
  • 2
0

Idk if you are still here but I found the solution. basically you should not save the tensorflow model into a pickle file but instead into h5 file

## save model
save_path = './model.h5'
model.save(save_path)
## load tensorflow model
model = keras.models.load_model(save_path)

This worked for me. Hope this helps you too.

Abdul Munim
  • 13
  • 1
  • 3
0

this worked for me:

import tensorflow as tf
path = './model.h5'
model.save(path )
loaded_model= tf.keras.models.load_model(path )
0

I have faced the same issue, but by saving the model as .h5 file worked for me. Now i'm able to load .h5 model.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 08 '22 at 02:57
  • This is a duplicate answer. A similar answer already exists. – Azhar Khan Nov 09 '22 at 09:03