Using Keras masking layer with 2D convolutions (Conv2D)











up vote
3
down vote

favorite












I'm trying to design a neural network including time dependent input with different lengths and I'm currently using a Masking layer.
This network worked well with TensorFlow version 1.9.0 but after updating to version 1.11.0, I get the following error:




Layer conv2d_1 does not support masking, but was passed an input_mask: Tensor("cnn1/Reshape_2:0", shape=(?, 81, 81), dtype=bool)




Any idea on how to solve this problem?



I'm using the following code:



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')









share|improve this question




























    up vote
    3
    down vote

    favorite












    I'm trying to design a neural network including time dependent input with different lengths and I'm currently using a Masking layer.
    This network worked well with TensorFlow version 1.9.0 but after updating to version 1.11.0, I get the following error:




    Layer conv2d_1 does not support masking, but was passed an input_mask: Tensor("cnn1/Reshape_2:0", shape=(?, 81, 81), dtype=bool)




    Any idea on how to solve this problem?



    I'm using the following code:



    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')









    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I'm trying to design a neural network including time dependent input with different lengths and I'm currently using a Masking layer.
      This network worked well with TensorFlow version 1.9.0 but after updating to version 1.11.0, I get the following error:




      Layer conv2d_1 does not support masking, but was passed an input_mask: Tensor("cnn1/Reshape_2:0", shape=(?, 81, 81), dtype=bool)




      Any idea on how to solve this problem?



      I'm using the following code:



      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')









      share|improve this question















      I'm trying to design a neural network including time dependent input with different lengths and I'm currently using a Masking layer.
      This network worked well with TensorFlow version 1.9.0 but after updating to version 1.11.0, I get the following error:




      Layer conv2d_1 does not support masking, but was passed an input_mask: Tensor("cnn1/Reshape_2:0", shape=(?, 81, 81), dtype=bool)




      Any idea on how to solve this problem?



      I'm using the following code:



      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 12:56

























      asked Nov 7 at 12:46









      nirR

      162




      162





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189730%2fusing-keras-masking-layer-with-2d-convolutions-conv2d%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189730%2fusing-keras-masking-layer-with-2d-convolutions-conv2d%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings