Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-232

Random Resized Crop (Seeded)

Problem

Perform a seeded random resized crop with aspect ratio 1.

Seed the random module, draw an area fraction uniformly from [scale_min, scale_max], set side = round(sqrt(fraction * H * W)) clipped to [1, min(H, W)], sample the top-left uniformly in the remaining range, then crop a side x side region and nearest-neighbor resize it to out_h x out_w.

Test cases

case 1
in: [[[1,2,3],[4,5,6],[7,8,9]],2,2,0.5,0.5,1]
expected: [[2,3],[5,6]]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9]],2,2,0.25,1,7]
expected: [[2,3],[5,6]]
case 3
in: [[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]],2,3,1,1,3]
expected: [[0,1,2],[8,9,10]]
Starter codePython
def random_resized_crop(image, out_h, out_w, scale_min, scale_max, seed):
    # Your code here
    pass

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