【问题标题】:Using Keras masking layer with 2D convolutions (Conv2D)使用带有 2D 卷积 (Conv2D) 的 Keras 遮罩层
【发布时间】:2019-04-10 21:33:51
【问题描述】:

我正在尝试设计一个包含不同长度的时间相关输入的神经网络,我目前正在使用掩蔽层。 该网络在 TensorFlow 1.9.0 版上运行良好,但在更新到 1.11.0 版后,我收到以下错误:

图层 conv2d_1 不支持遮罩,但传入了一个 input_mask:Tensor("cnn1/Reshape_2:0", shape=(?, 81, 81), dtype=bool)

关于如何解决这个问题的任何想法?

我正在使用以下代码:

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, \
    TimeDistributed, Dense, Masking, Activation, BatchNormalization

model= Sequential()
# first layer
model.add(TimeDistributed(Masking(0., input_shape=(81,81,3)),
                                  input_shape=(None,81,81,3), name='mask'))
# CNN layers
model.add(TimeDistributed(Conv2D(filters=10,
                                 kernel_size=5,
                                 strides=1,
                                 padding='same'),
                         name='cnn1'))

model.add(Activation('relu', name='relu1'))
model.add(BatchNormalization())
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))

# output layer
model.add(TimeDistributed(Dense(3, name='output')))
model.add(Activation('softmax'))

# compilation
model.compile(loss='categorical_crossentropy')

【问题讨论】:

    标签: python tensorflow neural-network keras


    【解决方案1】:

    用 tensorflow 替换您的 keras 导入:

    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import Conv2D, MaxPooling2D, \
        TimeDistributed, Dense, Masking, Activation, BatchNormalization
    

    【讨论】:

      猜你喜欢
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多