Home > Software design >  keras.models.load_model takes too long to import
keras.models.load_model takes too long to import

Time:12-01

I have a python project where I import keras.models.load_model:

from keras.models import load_model

This causes my project to launch in 3 to 4 seconds, how can I decrease the import time?

CodePudding user response:

Based on the benchmarks from this article, the format in which you save your weights affects how fast your model instantiates and loads saved weights.

It seems that the.h5 format is faster than the SavedModel format. However, if speed is really paramount to the function of your project then you may want to look at taking one of these steps, although it definitely involves some work:

  1. Reducing the precision of your model
  2. Reducing your model size by pruning weights
  3. Using TensorFlow lite (however note that some models aren't supported)
  • Related