Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-280

GridMask Masked Ratio

Problem

Compute the actual masked fraction of a GridMask pattern.

Let d = round(tile * ratio); a pixel is masked when (i mod tile) < d and (j mod tile) < d. Return the masked fraction of the H x W image rounded to 4 decimal places.

Test cases

case 1
in: [4,4,2,1]
expected: 1
case 2
in: [4,4,2,0.5]
expected: 0.25
case 3
in: [4,4,2,0]
expected: 0
case 4
in: [3,4,3,1]
expected: 1
Starter codePython
def gridmask_ratio(h, w, tile, ratio):
    # Your code here
    pass

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