首页 文章

TypeError:compile()缺少1个必需的位置参数:'self'

提问于
浏览
1

什么是model.copmpile中的'self'我尝试在keras模型中使用python运行代码我得到了这个错误

model.compile(loss =“binary_crossentropy”,optimizer ='adam',metrics = ['accuracy'])TypeError:compile()缺少1个必需的位置参数:'self'

2 回答

  • 2

    实例化Class然后使用方法......它应该是这样的

    model().compile()
    
    or 
    m = model()
    m.compile()
    
  • 0

    实际上你需要显示更多代码才能得到合适的答案,但我试一试:

    如果要编译模型,至少需要执行以下步骤:

    • from keras.models import Model

    • model = Model(inputs=in, outputs=out) - 其中 in 是输入图层, out 是输出图层 .

    • model.compile(loss=someLoss, optimizer=someOpt)

相关问题