如何用张量函数加载Returnn中训练网络的权值

2024-09-25 08:39:09 发布

您现在位置:Python中文网/ 问答频道 /正文

当尝试在一个已训练对象的多个历元上加载保存的权重时 returnn中的网络使用以下代码:

import tensorflow as tf
from returnn.Config import Config
from returnn.TFNetwork import TFNetwork

for i in range(1,11):
    modelFilePath = path/to/model/ + 'network.' + '%03d' % (i,)

    returnnConfig = Config()
    returnnConfig.load_file(path/to/configFile)
    returnnTfNetwork = TFNetwork(config=path/to/configFile, train_flag=False, eval_flag=True)

    returnnTfNetwork.construct_from_dict(returnnConfig.typed_value('network'))

    with tf.Session() as sess:
        returnnTfNetwork.load_params_from_file(modelFilePath, sess)

我得到以下错误:

Variables to restore which are not in checkpoint:
global_step_1

Variables in checkpoint which are not needed for restore:
global_step

Probably we can restore these:
(None)

Error, some entry is missing in the checkpoint

Tags: topathinfromimportconfigfortf
1条回答
网友
1楼 · 发布于 2024-09-25 08:39:09

问题是每次在循环中都要重新创建TFNetwork,而且每次都会为全局步骤创建一个新变量,必须调用不同的变量,因为每个变量都必须有一个唯一的名称。你知道吗

你可以在循环中这样做:

tf.reset_default_graph()

相关问题 更多 >