Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-393

Masked Patch Reconstruction Loss

Problem

Compute the masked patch reconstruction loss.

Return the mean squared error between pred and target over positions where mask is 1, rounded to 4 decimal places. When nothing is masked return 0.0.

Hint

Unmasked positions must not contribute to the loss or its normalizer.

Test cases

case 1
in: [[[1,2]],[[1,3]],[[1,0]]]
expected: 0
case 2
in: [[[0,0],[0,0]],[[1,1],[1,1]],[[1,1],[0,0]]]
expected: 1
case 3
in: [[[1,2],[3,4]],[[0,0],[0,0]],[[1,1],[1,1]]]
expected: 7.5
case 4
in: [[[5]],[[0]],[[0]]]
expected: 0
Starter codePython
def masked_recon_loss(pred, target, mask):
    # Your code here
    pass

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