繁体   English   中英

如何加载训练模型的权重,这些权重是用 tf.keras.models.save_model 保存的?

[英]How to load a trained model's weights, which were saved with tf.keras.models.save_model?

我训练了一个神经网络,没有任何检查点,最后我写了tf.keras.models.save_model(model, dirpath)来保存整个 model,它创建了以下文件:

savedmodel.pb 
assets/
variables/variables.index
variables/variables.data-00000-of-00001

I tried loading the model using new_model = tf.keras.models.load_model(dirpath) , but it gave a ValueError because I'm using a custom model (it seems, I created a class inheriting from tf.keras.Model ). 因此,我尝试实例化一个新的 model,然后使用

model = myModel(someArgs)
model.load_weights(dirpath/variables)

但是,我收到以下错误消息:

OSError:无法打开文件(无法打开文件:name = 'dirpath/variables',errno = 13,错误消息 = 'Permission denied',flags = 0,o_flags = 0)

那么如何将砝码加载到 model 上? 文件在那里,我只是不知道如何将它们放回我的 model 中。

想通了,我使用了错误的路径。 我需要做model.load_weights(dirpath/variables/variables) 吃了两个名为variables的文件,具有不同的扩展名( .data-00000-of-00001.index ),这就是您要调用的名称。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM