Python Tensorflow2.0a:为什么keras.models.load_model()比model.from_config()慢?

Python Tensorflow2.0a:为什么keras.models.load_model()比model.from_config()慢?,python,keras,tensorflow2.0,Python,Keras,Tensorflow2.0,我在Tensorflow2.0a中构建了两个自定义层和模型,扩展了Keras类。在所有这些方法中,我都实现了get\u config()和from\u config()方法。我还在CustomModel类中实现了model.save()方法(类似于顺序模型) def save(self、filepath、overwrite=True、include\u optimizer=True、**kwargs): 从tensorflow.python.keras.models导入saveu model#p

我在Tensorflow2.0a中构建了两个自定义层和模型,扩展了Keras类。在所有这些方法中,我都实现了
get\u config()
from\u config()
方法。我还在CustomModel类中实现了
model.save()
方法(类似于顺序模型)

def save(self、filepath、overwrite=True、include\u optimizer=True、**kwargs):
从tensorflow.python.keras.models导入saveu model#pylint:disable=g-import-not-at-top
保存模型(self、filepath、overwrite、include\u优化器)
这些方法允许我使用:

model.save(“model.h5”)
新_模型=keras.models.load_模型('model.h5',
自定义对象={
“CustomModel”:CustomModel,
“CustomLayer”:CustomLayer,#。。。
})
加载一个包含8层和9000个参数的模型大约需要30秒

但我也可以这样加载模型:

model.save_权重(“weights.h5”)
config=model.get_config()
新建_model=CustomModel.from_config(config)
新模型。荷载重量(“重量.h5”)
另一方面,对于同一型号,此方法需要0.6秒

第一种方法这么慢有什么原因吗?是否由于自定义模型/层的反序列化

在这种情况下,首选的方法是什么

我知道TF2是非常新的,但任何见解都将不胜感激