当前位置:   article > 正文

菜尼奥排错之keras TypeError: _init_subclassed_network() got an unexpected keyword argument ‘input‘_typeerror: forward() got an unexpected keyword arg

typeerror: forward() got an unexpected keyword argument 'num_classes

环境版本:

Ubuntu 18.04.2 LTS

Nvidia GeForce RTX2080super CUDA Version 10.0

tensorflow-gpu 1.13.1

keras 2.2.4-tf


报错信息:

诸如此类:

  1. TypeError: _init_subclassed_network() got an unexpected keyword argument 'input'
  2. TypeError: forward() got an unexpected keyword argument 'input'
  3. TypeError: Decoder() got an unexpected keyword argument 'input'
  4. TypeError: xxxxxx() got an unexpected keyword argument 'input'

本人是在运行Unet时出现的此问题:

  1. Traceback (most recent call last):
  2. File "unet.py", line 185, in <module>
  3. myunet.train()
  4. File "unet.py", line 164, in train
  5. model = self.get_unet()
  6. File "unet.py", line 154, in get_unet
  7. model = Model(input = inputs, output = conv10)
  8. File "/home/xxx/anaconda3/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 121, in __init__
  9. super(Model, self).__init__(*args, **kwargs)
  10. File "/home/xxx/anaconda3/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 84, in __init__
  11. self._init_subclassed_network(**kwargs)
  12. File "/home/xxx/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/checkpointable/base.py", line 442, in _method_wrapper
  13. method(self, *args, **kwargs)
  14. TypeError: _init_subclassed_network() got an unexpected keyword argument 'input'

原因分析:

查看自己环境中keras对应版本的函数调用方法,得知是版本不同造成的。

  1. #旧版本中代码:
  2. from keras.models import Model
  3. model = Model(input = inputs, output = conv10)
  4. #新版本中代码:
  5. from tensorflow.python.keras.models import Model
  6. model = Model(inputs = inputs, outputs = conv10)
  7. #出现UserWarning不用理会

同理, Decoder(inputs=out_sents_, encoder_hidden=en_hidden, encoder_outputs=en_output)函数报错也是一样的原因。

  1. results = Decoder(inputs=out_sents_, encoder_hidden=en_hidden, encoder_outputs=en_output)
  2. #修改如下
  3. results = Decoder(out_sents_, en_hidden)

解决方案:

方案一:"input"修改为"inputs","output"修改为"outputs"。

  1. model = Model(input = inputs, output = conv10)
  2. #修改如下,参数根据自己的需要调整
  3. model = Model(inputs = inputs, outputs = conv10)

方案二:删除"input"/"output"参数名即可。

  1. model = Model(input = inputs, output = conv10)
  2. #修改如下,参数根据自己的需要调整
  3. model = Model(inputs, conv10)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/286468
推荐阅读
相关标签
  

闽ICP备14008679号