2017-02-22 36 views
2

我正在keras中实现ApesNet。它有一个有跳过连接的ApesBlock。我如何将这添加到keras的顺序模型中? ApesBlock有两个平行层,最后通过逐元相加合并。 enter image description here在keras中实现跳过连接

回答

8

最简单的答案是不使用顺序模型这一点,使用功能API代替,实施跳过连接(也称为残留连接)然后很容易,如从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

所以,这不会是backprop期间的问题,因为y有卷积的权重和z有新的张量? –

+1

@Siddhartharao不,因为这是所有符号的梯度可以由TF/Theano直接计算。 –