Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-192

Patch Merging Downsample

Problem

Downsample an image by merging each 2x2 block into one 4-value cell (Swin patch merging without the linear layer).

For every non-overlapping block return [top-left, top-right, bottom-left, bottom-right]. Both dimensions are even.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [[[1,2,3,4]]]
case 2
in: [[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]]
expected: [[[0,1,4,5],[2,3,6,7]],[[8,9,12,13],[10,11,14,15]]]
case 3
in: [[[1,2,3,4],[5,6,7,8]]]
expected: [[[1,2,5,6],[3,4,7,8]]]
Starter codePython
def patch_merge(image):
    # Your code here
    pass

3 test cases · run your code against them in the editor