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

4

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.

Fourposter answered 30/3, 2022 at 11:37 Comment(9)
Hi @abdalla Adding ./ in front of the file name like this filename = open("./loan_model3.pkl", "rb") should help. Let us know if the error still persists. Thanks!Dyedinthewool
Hi @Tfer3 , i've tried that but unfortunately the error still there .Fourposter
Is the pickle file and the notebook in the same folder?Dyedinthewool
Hi @Tfer3 sorry for late reply , yes they are both in the same folder , im using jupyter notebook , so they are in the same folder i saved my .py fileFourposter
Could you please share the steps used to save the model? Thanks!Dyedinthewool
Hey, were you able to solve this problem ?? I am facing the same issue currently.Scout
Any solution? Currently facing sameLatex
Same issue here as well ... please adviseGeniagenial
Any solution for this issue? Currently encountering the sameEnthrone
S
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')
Stingo answered 3/8, 2022 at 18:27 Comment(0)
D
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.

Danelaw answered 16/5, 2022 at 6:19 Comment(2)
Hi Abdul Munim , Thank you for your response , i will try this and revert back to you.Fourposter
My apologies for the late reply , iw ill give it a try , so sorry fro replying late had some problems here.Fourposter
L
0

this worked for me:

import tensorflow as tf
path = './model.h5'
model.save(path )
loaded_model= tf.keras.models.load_model(path )
Lownecked answered 23/5, 2022 at 0:14 Comment(0)
S
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.

Swanskin answered 4/11, 2022 at 15:57 Comment(2)
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.Lanti
This is a duplicate answer. A similar answer already exists.Microcyte

© 2022 - 2024 — McMap. All rights reserved.