Error , Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ram to unpickle a file

Viewed 3548

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.

3 Answers

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')

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.

this worked for me:

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