层 time_distributed_30 的输入 0 与层不兼容:预期 ndim=5,发现 ndim=4。收到完整形状:(无,无,无,无)

时间:2021-06-09 06:41:49

标签: keras deep-learning bilstm

  1. 我正在尝试对 10 个类的 MSTAR 数据集进行分类
  2. 我使用了包含 15 个时间步长的 DCNN 和 BILSTM 的模态

我的问题是:

  1. 如何克服错误
  2. 如何获得好的分类结果。

我的代码是:

inputs=Input(shape=(15,60,60,3))
model = Sequential()
# 1st Convolutional Layer
model.add(TimeDistributed(Conv2D(filters=16 ,kernel_size=(5,5), padding='valid'),input_shape=(15,60,60,3)))
model.add(TimeDistributed(Activation('relu')))
# Batch Normalisation
model.add(TimeDistributed(BatchNormalization()))
# Pooling 
model.add(TimeDistributed(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='valid')))

# 2nd Convolutional Layer
model.add(TimeDistributed(Conv2D(filters=32, kernel_size=(5,5), padding='valid')))
model.add(TimeDistributed(Activation('relu')))
# Batch Normalisation
model.add(TimeDistributed(BatchNormalization()))
# Pooling
model.add(TimeDistributed(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='valid')))

# 3rd Convolutional Layer
model.add(TimeDistributed(Conv2D(filters=64, kernel_size=(5,5), padding='valid')))
model.add(Activation('relu'))
# Batch Normalisation
model.add(TimeDistributed(BatchNormalization()))
# Pooling
model.add(TimeDistributed(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='valid')))

# 4th Convolutional Layer
model.add(TimeDistributed(Conv2D(filters=128, kernel_size=(4,4), padding='valid')))
model.add(TimeDistributed(Activation('relu')))
# Batch Normalisation
model.add(TimeDistributed(BatchNormalization()))
model.add(TimeDistributed(Flatten()))
#add dropout
model.add(Dropout(0.0))
#bidirectional lstm
model.add(Bidirectional(LSTM(1024,activation='tanh',return_sequences=True)))
#2 nd bidirectional layer
model.add(Bidirectional(LSTM(1024,activation='tanh',return_sequences=False)))
# Output Layer
model.add(Dense(10))
model.add(Activation('softmax'))

# (4) Compile 
model.compile(loss='categorical_crossentropy', optimizer='adam',\
 metrics=['accuracy'])
model.summary()

0 个答案:

没有答案