All problems
Random Erasing
Problem
Erase a random square region of an image with a seeded RNG.
Seed the random module; the square side is max(1, round(sqrt(area_frac * H * W))) clipped to the image, the top-left is uniform in the remaining range, and the region is filled with 0.
Test cases
case 1
in: [[[5,5,5,5],[5,5,5,5],[5,5,5,5],[5,5,5,5]],0.25,2]
expected: [[0,0,5,5],[0,0,5,5],[5,5,5,5],[5,5,5,5]]
case 2
in: [[[5,5,5,5],[5,5,5,5],[5,5,5,5],[5,5,5,5]],0.1,0]
expected: [[5,5,5,5],[5,5,5,5],[5,5,5,5],[5,5,5,0]]
case 3
in: [[[1,2],[3,4]],0.5,1]
expected: [[0,2],[3,4]]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]],1,0]
expected: [[0,0,0],[0,0,0],[0,0,0]]
Starter codePython
def random_erasing(image, area_frac, seed):
# Your code here
pass4 test cases · run your code against them in the editor