【问题标题】:Theano/lasagne: ValueError: mismatch: got 10 values to set 0 parametersTheano/lasagne: ValueError: mismatch: got 10 values to set 0 parameters
【发布时间】:2016-04-21 07:48:00
【问题描述】:

我在 theano/lasagne 中训练了一个神经网络,并用这段代码保存了网络参数:

np.savez('model.npz', *lasagne.layers.get_all_param_values(network))

现在我想加载模型并将参数设置为网络,以便测试它是否正常工作。我正在用这段代码加载参数:

with np.load('model.npz') as f:
        param_values = [f['arr_%d' % i] for i in range(len(f.files))]

然后我尝试将网络的参数设置为加载的参数,如下所示:

lasagne.layers.set_all_param_values(self._output_layer, param_values, allow_input_downcast=True)

然后我得到这个错误:

> Traceback (most recent call last):
  File "snake_player.py", line 406, in <module>
    player = SnakePlayer()
  File "snake_player.py", line 99, in __init__
    self.loadModel()
  File "snake_player.py", line 328, in loadModel
    lasagne.layers.set_all_param_values(self._output_layer, param_values, allow_input_downcast=True, trainable=True)
  File "C:\Anaconda2\lib\site-packages\lasagne\layers\helper.py", line 446, in set_all_param_values
    (len(values), len(params)))
ValueError: mismatch: got 10 values to set 0 parameters

但是当我得到网络中的所有参数并查看长度时,有10个参数。

x = lasagne.layers.get_all_param_values(self._output_layer)
len(x) # 10

所以参数的数量是相同的,不知何故我仍然得到这个错误。知道为什么吗?我忽略了什么吗?

感谢您的帮助。

【问题讨论】:

    标签: python theano lasagne


    【解决方案1】:

    如果您在没有allow_input_downcast=True 标志的情况下调用set_all_param_values,则不会发生这种情况。

    【讨论】:

      猜你喜欢
      • 2022-11-12
      • 2021-12-31
      • 2020-10-10
      • 1970-01-01
      • 2017-12-23
      • 2020-11-19
      • 1970-01-01
      • 2018-12-29
      • 2020-10-26
      相关资源
      最近更新 更多