def _deconv_shortcut(x, residual, output_shape):
# Expand channels of shortcut to match residual.
# Stride appropriately to match residual (width, height).
# Should be int if network architecture is correctly configured.
stride_width = residual._keras_shape[1] / x._keras_shape[1]
stride_height = residual._keras_shape[2] / x._keras_shape[2]
equal_channels = residual._keras_shape[3] == x._keras_shape[3]
shortcut = x
if stride_width > 1 or stride_height > 1 or not equal_channels:
shortcut = Deconvolution2D(
residual._keras_shape[3], 1, 1,
subsample=(stride_width, stride_height),
output_shape=output_shape,
init="he_normal", border_mode="valid")(x)
return merge([shortcut, residual], mode="sum")
# Builds a residual block with repeating bottleneck blocks.
评论列表
文章目录