Tensorflow 在Keras中使用带有CONVLSM2D层的掩蔽层

Tensorflow 在Keras中使用带有CONVLSM2D层的掩蔽层,tensorflow,keras,keras-2,Tensorflow,Keras,Keras 2,我正在尝试使用Keras(2.0.6)和TensorFlow后端(1.2.1)屏蔽卷积LSTM层中丢失的数据: 但是,我得到以下值错误: ValueError: Shape must be rank 4 but is rank 2 for 'conv_lst_m2d_1/while/Tile' (op: 'Tile') with input shapes: [?,64,64,1], [2]. 如何在convlsm2d层上使用掩蔽?在将掩蔽层应用于任意张量(如图像)时,Keras似乎存在问题。我

我正在尝试使用Keras(2.0.6)和TensorFlow后端(1.2.1)屏蔽卷积LSTM层中丢失的数据:

但是,我得到以下值错误:

ValueError: Shape must be rank 4 but is rank 2 for 'conv_lst_m2d_1/while/Tile' (op: 'Tile') with input shapes: [?,64,64,1], [2].

如何在convlsm2d层上使用掩蔽?

在将掩蔽层应用于任意张量(如图像)时,Keras似乎存在问题。我可以找到一个(远不理想的)解决方法,在应用遮罩层之前将输入展平。因此,考虑到原始模型:

model = Sequential()
model.add(Masking(mask_value=0., input_shape=(n_timesteps, n_width, n_height, n_channels)))
model.add(ConvLSTM2D(filters=64, kernel_size=(3, 3)))
我们可以修改如下:

input_shape = (n_timesteps, n_width, n_height, n_channels)
model = Sequential()
model.add(TimeDistributed(Flatten(), input_shape=input_shape))
model.add(TimeDistributed(Masking(mask_value=0.)))
model.add(TimeDistributed(Reshape(input_shape[1:])))
model.add(ConvLSTM2D(filters=64, kernel_size=(3, 3)))
此解决方案在图形中添加了额外的计算,但没有额外的参数

input_shape = (n_timesteps, n_width, n_height, n_channels)
model = Sequential()
model.add(TimeDistributed(Flatten(), input_shape=input_shape))
model.add(TimeDistributed(Masking(mask_value=0.)))
model.add(TimeDistributed(Reshape(input_shape[1:])))
model.add(ConvLSTM2D(filters=64, kernel_size=(3, 3)))