__init __()得到了意外的关键字参数'inputs' [英] __init__() got an unexpected keyword argument 'inputs'

查看:260
本文介绍了__init __()得到了意外的关键字参数'inputs'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Model:
    def __init__(self):    
        self.model = Sequential()
        self.model.add(Conv2D(24, 3, 2, 'valid', input_shape=(75, 75, 3)))
        self.model.add(BatchNormalization())
        self.model.add(Conv2D(24, 3, 2))
        self.model.add(BatchNormalization())
        self.model.add(Conv2D(24, 3, 2))
        self.model.add(BatchNormalization())
        self.model.add(Conv2D(24, 3, 2))
        self.model.add(BatchNormalization())
        self.model.add(Flatten())

    def get_model(self):
        return self.model

class CNN_MLP:
    def __init__(self):
        model = Model()
        self.model = model.get_model()
        self.optimizer = optimizers

    def get_model(self): 
        self.model = self.extend(self.model)
        return self.model

    def extend(self, model):
        self.model = model
        self.sequence = Input(shape=(75, 75, 3), name='Sequence')
        self.features = Input(shape=(11, ), name='Features')
        conv_sequence = self.model(self.sequence)

         merged_features = concatenate([conv_sequence, self.features])
         fc1 = Dense(256, activation='relu')(merged_features)
         fc2 = Dense(256, activation='relu')(fc1)
         logits = Dense(10, activation='softmax')(fc2)

         # In the following statement I am getting the error
         self.model = Model(inputs=[self.sequence, self.features], outputs=[logits])
         return self.model

我正在尝试执行以上代码,并遇到上述错误.我使用的是Keras的 2.2.4-tf 版本.我无法理解该错误的原因.

I am trying to execute the above code and getting the above mentioned error. I am on version 2.2.4-tf of Keras. I am unable to understand the reason behind the error.

有人可以帮助我识别并解决问题吗?

Could anyone help me identifying and thus fixing the issue?

谢谢!

完整追溯:

<ipython-input-29-5112dc1649fd> in <module>()
      1 if args.model == 'CNN_MLP':
      2   model = CNN_MLP()
----> 3   model = model.get_model()

1 frames

<ipython-input-28-6491bbcf21c5> in get_model(self)
      6 
      7   def get_model(self):
----> 8     self.model = self.extend(self.model)
      9     return self.model
     10 

<ipython-input-28-6491bbcf21c5> in extend(self, model)
     20     logits = Dense(10, activation='softmax')(fc2)
     21 
---> 22     self.model = Model(inputs=[self.sequence, self.features], outputs=[logits])
     23     return self.model

TypeError: __init__() got an unexpected keyword argument 'inputs'

推荐答案

您定义了一个名为Model的类,因此它遮盖了该类keras.models.Model,因此当您尝试实例Model时,它将使用您的类来代替的Keras'.

You defined a class called Model, so this shadows the class keras.models.Model, so when you try to instance Model, it uses your class instead of Keras'.

一种简单的解决方案是完全限定通话中的程序包名称:

A simple solution would be to fully qualify the package name in the call:

self.model = keras.models.Model(inputs=[self.sequence, self.features], outputs=[logits])

这篇关于__init __()得到了意外的关键字参数'inputs'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆