def METHOD_NAME(x, target_layer, target_shape, data_format):
    if data_format == 'channels_first':
        new_shape = tf.shape(target_layer)[2:]
        x = _permute_dimensions(x, [0, 2, 3, 1])
        x = tf.image.resize_nearest_neighbor(x, new_shape)
        x = _permute_dimensions(x, [0, 3, 1, 2])
        x.set_shape((None, None, target_shape[2], target_shape[3]))
        return x
    elif data_format == 'channels_last':
        new_shape = tf.shape(target_layer)[1:3]
        x = tf.image.resize_nearest_neighbor(x, new_shape)
        x.set_shape((None, target_shape[1], target_shape[2], None))
        return x
    else:
        raise ValueError('Unknown data_format: ' + str(data_format))