【发布时间】:2021-09-14 15:27:42
【问题描述】:
这是我根据 Liu, Gibson, et al 2017 (https://arxiv.org/abs/1708.09022) 的论文制作的 keras 模型。如图1所示。
我有 3 个问题-
- 我不确定我是否按照论文正确使用了连接。
- 我收到 AttributeError:'KerasTensor' 对象在 model4.add 上没有属性 'add' 变平。之前没有出现此错误
- 之前,唯一的错误是 ValueError:
Concatenate层需要具有匹配形状的输入,但 concat 轴除外。得到输入形状:[(None, 310, 1, 16), (None, 310, 1, 32), (None, 310, 1, 64)],我也不知道如何处理。
model1= Sequential()
model2= Sequential()
model3= Sequential()
model4= Sequential()
input_sh = (619,2,1)
model1.add(Convolution1D(filters=16, kernel_size=21, padding='same', activation='LeakyReLU', input_shape=input_sh))
model1.add(MaxPooling2D(pool_size=(2,2), padding='same'))
model1.add(BatchNormalization())
model1.summary()
model2.add(Convolution1D(filters=32, kernel_size=11, padding='same', activation='LeakyReLU', input_shape= input_sh))
model2.add(MaxPooling2D(pool_size=(2,2), padding='same'))
model2.add(BatchNormalization())
model2.summary()
model3.add(Convolution1D(filters=64, kernel_size=5, padding='same', activation='LeakyReLU', input_shape= input_sh))
model3.add(MaxPooling2D(pool_size=(2,2), padding='same'))
model3.add(BatchNormalization())
model3.summary()
model4 = concatenate([model1.output, model2.output, model3.output], axis= -1)
model4.add(Flatten()) # Line with error
model4.add(Dense(2048, activation='tanh'))
model4.add(Dropout(.5))
model4.add(Dense(len(dic), activation="softmax")) #len(dic) = 19
model4.summary()
输出如下-
Model: "sequential_59"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_45 (Conv1D) (None, 619, 2, 16) 352
_________________________________________________________________
max_pooling2d_45 (MaxPooling (None, 310, 1, 16) 0
_________________________________________________________________
batch_normalization_45 (Batc (None, 310, 1, 16) 64
=================================================================
Total params: 416
Trainable params: 384
Non-trainable params: 32
_________________________________________________________________
Model: "sequential_60"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_46 (Conv1D) (None, 619, 2, 32) 384
_________________________________________________________________
max_pooling2d_46 (MaxPooling (None, 310, 1, 32) 0
_________________________________________________________________
batch_normalization_46 (Batc (None, 310, 1, 32) 128
=================================================================
Total params: 512
Trainable params: 448
Non-trainable params: 64
_________________________________________________________________
Model: "sequential_61"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_47 (Conv1D) (None, 619, 2, 64) 384
_________________________________________________________________
max_pooling2d_47 (MaxPooling (None, 310, 1, 64) 0
_________________________________________________________________
batch_normalization_47 (Batc (None, 310, 1, 64) 256
=================================================================
Total params: 640
Trainable params: 512
Non-trainable params: 128
_________________________________________________________________
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-bf7ad914aa4e> in <module>()
44 model4 = concatenate([model1.output, model2.output, model3.output], axis= -1)
45
---> 46 model4.add(Flatten())
47 model4.add(Dense(2048, activation='tanh'))
48 model4.add(Dropout(.5))
AttributeError: 'KerasTensor' object has no attribute 'add'
【问题讨论】:
标签: python tensorflow keras deep-learning concatenation