Implementing skip connections in keras

前端 未结 2 1366
遥遥无期
遥遥无期 2021-02-01 19:50

I am implementing ApesNet in keras. It has an ApesBlock that has skip connections. How do I add this to a sequential model in keras? The ApesBlock has two parallel layers that m

相关标签:
2条回答
  • In case anyone still has the same issue and the merge layer didn't work.

    I couldn't find merge in the Keras documentation, as written by Dr. Snoopy. And I get a type error 'module' object is not callable.

    Instead I added an Add layer.

    So the same example as Dr. Snoopy's answer would be:

    from keras.layers import Add, Convolution2D, Input
    
    # input tensor for a 3-channel 256x256 image
    x = Input(shape=(3, 256, 256))
    # 3x3 conv with 3 output channels (same as input channels)
    y = Convolution2D(3, 3, 3, border_mode='same')(x)
    # this returns x + y.
    z = Add()([x, y])
    
    0 讨论(0)
  • 2021-02-01 20:18

    The easy answer is don't use a sequential model for this, use the functional API instead, implementing skip connections (also called residual connections) are then very easy, as shown in this example from the functional API guide:

    from keras.layers import merge, Convolution2D, Input
    
    # input tensor for a 3-channel 256x256 image
    x = Input(shape=(3, 256, 256))
    # 3x3 conv with 3 output channels (same as input channels)
    y = Convolution2D(3, 3, 3, border_mode='same')(x)
    # this returns x + y.
    z = merge([x, y], mode='sum')
    
    0 讨论(0)
提交回复
热议问题