'Model' 对象没有属性 'add' Keras 自动编码器

'Model' object has no attribute 'add' Keras Autoencoder

我想为我的自动编码器添加初始值设定项

autoencoder=Model(input_img, decoded)
autoencoder.add(Dense(64,kernel_initializer='random_uniform',
                bias_initializer='zeros'))

但是我收到了这个错误

'Model' object has no attribute 'add'

如果你想按顺序添加图层(使用.add()方法),你需要使用像这样的Sequential()模型:

autoencoder = Sequential()
autoencoder.add(Dense(64,kernel_initializer='random_uniform',
                bias_initializer='zeros',input_shape=your_input_shape))

您可以通过阅读 guide to Sequential model and its counterpart for the functional API 找到更完整的解释。