Search code examples
pythonkeraspickle

An error in loading deep learning model via pickle


I made a deep learning model using Keras and stored it in a folder named model.pkl and for loading the model for deployment I used the code i.e.

import pickle
model = pickle.load(open('/home/samar/Desktop/ckd/model.pkl', 'rb'))
prediction = model.predict(data)

But it returned me as

IsADirectoryError: [Errno 21] Is a directory: '/home/samar/Desktop/ckd/model.pkl'

Though the folder is present there still it's giving the error.

I saved the model via model.save('model.pkl')


Solution

  • Using the model.save() method doesn't actually pickle it, you would want to use the built-in model loader from keras to load your model, like this:

    model = keras.models.load_model('/home/samar/Desktop/ckd/model.pkl')
    prediction = model.predict(data)