Q:

keras: importing load_model takes too long

I'm attempting to put a Python project on a flashdrive. I'm using WinPython to accomplish this. One thing that I've found is that some operations in the Python program are a lot slower. This makes sense because it's on a USB. One place this is especially evident is during import statements. Mostly, I was able to more selectively import things and things were fine for the most part. 
However, I'm using a keras model in my project. And to do this, I am loading my hdf5 file with load_model from the keras.models module. When I run this on WinPython it takes over ten minutes to import! How can I decrease this import time?

A:

You can convert your hdf5 model to a json_file and save the weights in an h5 file. Do this on a "normal" machine where the function imports not as slowly. Then, in WinPython on your flashdrive, using the model_from_json and load_weights functions you can load the model. The import time is much faster. It works like this:
This script will convert an hdf5 file into a json file and save the weights of the model. Run this on a python installation on a machine that can handle the import.
from keras.models import load_model

model = load_model("my_model.hdf5")
model_json = model.to_json()
with open("my_json_model.json", 'w') as json_file:
    json_file.write(model_json)

model.save_weights("weight_model.h5")

Then, to load your model in your WinPython, do something like this:
from keras.models import model_from_json

with open("my_json_model.json", 'r') as json_file:
    loaded_json = json_file.read()
emotion_classifier = model_from_json(loaded_json)
emotion_classifier.load_weights("weight_model.h5")

I found this import to be MUCH faster in the WinPython.
You can learn more about loading keras models in different ways here.

