lanenet(tensorflow运行)出现错误TypeError: __init__() takes 1 positional argument but 2 were given

运行lanenet训练数据集出现错误

  File "tools/test_lanenet.py", line 117, in test_lanenet
    saver = tf.train.Checkpoint(variables_to_restore)
TypeError: __init__() takes 1 positional argument but 2 were given

    # define moving average version of the learned variables for eval
    with tf.compat.v1.variable_scope(name_or_scope='moving_avg'):
        variable_averages = tf.train.ExponentialMovingAverage(
            CFG.SOLVER.MOVING_AVE_DECAY)
        variables_to_restore = variable_averages.variables_to_restore()

    # define saver
    saver = tf.train.Checkpoint(variables_to_restore)

该回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下:
根据代码和错误提示,可能是因为tf.train.Checkpoint()函数需要0个参数,但是你提供了1个variables_to_restore参数,因此会导致TypeError错误。

可以尝试将saver的定义改为以下代码:

saver = tf.train.Checkpoint()

这样就不会再出现TypeError错误了,但是需要注意的是,这样的定义方式可能会导致模型的变量没有被正确还原(restore),因此需要根据具体情况进行修改。

如果你需要使用variables_to_restore参数,可以尝试使用tf.compat.v1.train.Saver()函数来定义saver,如下所示:

saver = tf.compat.v1.train.Saver(variables_to_restore)

这样就可以正确地定义saver,并根据variables_to_restore参数来还原模型的变量。


如果以上回答对您有所帮助,点击一下采纳该答案~谢谢