I saved my keras model into .h5 format. Again I've loaded that .h5 file into my colab and tried to predict with that model. model.save("/content/drive/My Drive/Datasets/sentiment_analysis.h5")

from keras.models import load_model
loaded_model = load_model("/content/drive/MyDrive/Datasets/sentiment_analysis.h5")
loaded_model.predict("i love machine learning and google")

It's giving error list index out of range.

IndexError: list index out of range

Try these:

  1. import everything from tensorflow keras API.
  2. tf.keras.models.load_model("./saved_models/our_model.h5", compile=False) (make sure you have model and weights both in the file)
| improve this answer | |
  • $\begingroup$ it's not working. I'm doing this model.save(KERAS_MODEL) w2v_model.save(WORD2VEC_MODEL) pickle.dump(tokenizer, open(TOKENIZER_MODEL, "wb"), protocol=0) pickle.dump(encoder, open(ENCODER_MODEL, "wb"), protocol=0) and loading the keras_model file $\endgroup$ – Nithin Reddy Aug 5 at 14:22
  • $\begingroup$ i have 4 files. encoder.pkl, model.h5, model.w2v and tokenizer.pkl but i'm loading only model.h5 and trying to predict $\endgroup$ – Nithin Reddy Aug 5 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.