How to use an exported model from google colab in Pycharm

Viewed 1700

I have a LSTM Keras Tensorflow model trained and exported in .h5 (HDF5) format. My local machine does not support keras tensorflow. I have tried installing. But does not work.

Therefore, i used google colabs and exported the model.

I would like to know, how i can use the exported model in pycharm

Edit : I just now installed tensorflow on my machine

Thanks in Advance

3 Answers

Found the answer :

I ve exported the model as follows

model.save('/content/drive/My Drive/Colab Notebooks/model.h5')

Then i downloaded the file and saved in the folder where my other codes are. I have installed tensorflow.

Next i load the code and predicted using the saved model as follows.

import keras
model=keras.models.load_model('/content/drive/My Drive/Colab Notebooks/model.h5')
model.predict(instace)

You still need keras and tensorflow to use the model.

The accepted answer is correct but it misses that you first need to mount the "/content/drive"

from google.colab import drive
drive.mount('/content/drive')

Then you can save the weights of the model:

model.save_weights('my_model_weights.h5')

..or even save the whole model :

model.save('my_model.h5')

Once done, disconnect your mounted point using:

drive.flush_and_unmount()
Related