Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-188

Conv Patch Embedding

Problem

Apply a patch embedding as an unfold plus dot product.

For every non-overlapping patch (row-major) compute the sum of pixel * weight over the flattened patch, where weight has patch * patch entries. Return the list of outputs rounded to 4 decimal places.

Test cases

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

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