简体   繁体   English

如何从 Colaboratory 中保存的检查点加载 TensorFlow Keras model?

[英]How to load TensorFlow Keras model from a saved checkpoint in Colaboratory?

I've built and trained an RNN model in Colaboratory, and saved it using the checkpoint callback:我在 Colaboratory 中构建并训练了一个 RNN model,并使用检查点回调将其保存:

tf.keras.callbacks.ModelCheckpoint( filepath=chkpt_p, save_weights_only=False)

And the saved data looks like this:保存的数据如下所示:

在此处输入图像描述

If I understand correctly, this directory includes both the model and the weights.如果我没理解错的话,这个目录包括 model 和权重。 Which function should I use to restore it (in another runtime)?我应该使用哪个 function 来恢复它(在另一个运行时)?

This worked for me:这对我有用:

model = tf.keras.models.load_model(save_dir,compile=False)

I had one issue with using tf.saved_model.load , which doesn't produce a keras object, and one TF not finding the loss function with compile=True .我在使用tf.saved_model.load时遇到了一个问题,它不会产生 keras object,并且一个 TF 找不到损失 function 与compile=True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Tensorflow 检查点将权重加载到 Keras 模型 - How to load_weights to a Keras model from a Tensorflow checkpoint 加载张量流检查点作为keras模型 - Load tensorflow checkpoint as keras model 来自检查点的负载权重在 keras model 中不起作用 - Load weights from checkpoint not working in keras model 如何加载用 saved_model 保存的 tensorflow keras model 以使用预测 function? - How to load a tensorflow keras model saved with saved_model to use the predict function? 如何在张量流中读取Keras检查点? - How to read Keras checkpoint in tensorflow? 使用TPU模式时,如何从Google Colaboratory保存Tensorflow Checkpoint文件? - How to save a Tensorflow Checkpoint file from Google Colaboratory in when using TPU mode? 无法在 Keras 2.1.0(使用 Tensorflow 1.3.0)中保存的 Keras 2.4.3(使用 Tensorflow 2.3.0)中加载 Keras 模型 - Unable to load Keras model in Keras 2.4.3 (with Tensorflow 2.3.0) that was saved in Keras 2.1.0 (with Tensorflow 1.3.0) 如何使用从 save_weights 保存的张量流模型加载和预测? - How to load and predict with a tensorflow model saved from save_weights? 如何加载 keras model 另存为.pb - How to load a keras model saved as .pb 如何加载和测试特定的TensorFlow保存的模型? - How to load and test a specific TensorFlow saved model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM