def crop_and_concat(inputs1, inputs2, name='crop_concat'):
"""Concates two features maps
concates different sizes feature maps cropping the larger map
concatenation across output channels
Args:
inputs1: A `Tensor`
inputs2: A `Tensor`
Returns:
concated output tensor
"""
with tf.name_scope(name):
inputs1_shape = tf.shape(inputs1)
inputs2_shape = tf.shape(inputs2)
# offsets for the top left corner of the crop
offsets = [0, (inputs1_shape[1] - inputs2_shape[1]) // 2,
(inputs1_shape[2] - inputs2_shape[2]) // 2, 0]
size = [-1, inputs2_shape[1], inputs2_shape[2], -1]
inputs1_crop = tf.slice(inputs1, offsets, size)
return tf.concat([inputs1_crop, inputs2], axis=3)
评论列表
文章目录