【发布时间】:2021-05-03 22:05:43
【问题描述】:
我建立了一个模型,该模型将时间序列的 3 个图像和 5 个数字信息作为输入,并生成时间序列的接下来的三个图像。 我通过以下方式完成了这项工作:
- 构建用于处理图像的 ConvLSTM2D 模型(与 Keras 文档here 中列出的示例非常相似)。输入大小=(3x128x128x3)
- 为具有几个密集层的表格数据构建一个简单模型。输入大小=(1,5)
- 连接这两个模型
- 有一个 Conv3D 模型可以生成接下来的 3 张图像
LSTM 模型产生大小为 393216 (3x128x128x8) 的输出。现在我必须将表格模型的输出设置为 49,152,这样我才能在下一层获得 442368 (3x128x128x9) 的输入大小。因此,表格模型的 Dense 层的这种不必要的膨胀使得原本高效的 LSTM 模型表现得非常糟糕。
有没有更好的方法来连接这两个模型?有没有办法让表格模型的密集层输出 10?
型号:
x_input = Input(shape=(None, 128, 128, 3))
x = ConvLSTM2D(32, 3, strides = 1, padding='same', dilation_rate = 2,return_sequences=True)(x_input)
x = BatchNormalization()(x)
x = ConvLSTM2D(16, 3, strides = 1, padding='same', dilation_rate = 2,return_sequences=True)(x)
x = BatchNormalization()(x)
x = ConvLSTM2D(8, 3, strides = 1, padding='same', dilation_rate = 2,return_sequences=True)(x)
x = BatchNormalization()(x)
x = Flatten()(x)
# x = MaxPooling3D()(x)
x_tab_input = Input(shape=(5))
x_tab = Dense(100, activation="relu")(x_tab_input)
x_tab = Dense(49152, activation="relu")(x_tab)
x_tab = Flatten()(x_tab)
concat = Concatenate()([x, x_tab])
output = Reshape((3,128,128,9))(concat)
output = Conv3D(filters=3, kernel_size=(3, 3, 3), activation='relu', padding="same")(output)
model = Model([x_input, x_tab_input], output)
model.compile(loss='mae', optimizer='rmsprop')
模型总结:
Model: "functional_3"
______________________________________________________________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
======================================================================================================================================================
input_4 (InputLayer) [(None, None, 128, 128, 3)] 0
______________________________________________________________________________________________________________________________________________________
conv_lst_m2d_9 (ConvLSTM2D) (None, None, 128, 128, 32) 40448 input_4[0][0]
______________________________________________________________________________________________________________________________________________________
batch_normalization_9 (BatchNormalization) (None, None, 128, 128, 32) 128 conv_lst_m2d_9[0][0]
______________________________________________________________________________________________________________________________________________________
conv_lst_m2d_10 (ConvLSTM2D) (None, None, 128, 128, 16) 27712 batch_normalization_9[0][0]
______________________________________________________________________________________________________________________________________________________
batch_normalization_10 (BatchNormalization) (None, None, 128, 128, 16) 64 conv_lst_m2d_10[0][0]
______________________________________________________________________________________________________________________________________________________
input_5 (InputLayer) [(None, 5)] 0
______________________________________________________________________________________________________________________________________________________
conv_lst_m2d_11 (ConvLSTM2D) (None, None, 128, 128, 8) 6944 batch_normalization_10[0][0]
______________________________________________________________________________________________________________________________________________________
dense (Dense) (None, 100) 600 input_5[0][0]
______________________________________________________________________________________________________________________________________________________
batch_normalization_11 (BatchNormalization) (None, None, 128, 128, 8) 32 conv_lst_m2d_11[0][0]
______________________________________________________________________________________________________________________________________________________
dense_1 (Dense) (None, 49152) 4964352 dense[0][0]
______________________________________________________________________________________________________________________________________________________
flatten_3 (Flatten) (None, None) 0 batch_normalization_11[0][0]
______________________________________________________________________________________________________________________________________________________
flatten_4 (Flatten) (None, 49152) 0 dense_1[0][0]
______________________________________________________________________________________________________________________________________________________
concatenate (Concatenate) (None, None) 0 flatten_3[0][0]
flatten_4[0][0]
______________________________________________________________________________________________________________________________________________________
reshape_2 (Reshape) (None, 3, 128, 128, 9) 0 concatenate[0][0]
______________________________________________________________________________________________________________________________________________________
conv3d_2 (Conv3D) (None, 3, 128, 128, 3) 732 reshape_2[0][0]
======================================================================================================================================================
Total params: 5,041,012
Trainable params: 5,040,900
Non-trainable params: 112
______________________________________________________________________________________________________________________________________________________
【问题讨论】:
-
除了我的回答之外,我还建议查看 U-Nets - 跳过连接似乎适合这个问题。我希望这一切都有帮助:)
标签: tensorflow machine-learning keras lstm