Yes, the problem definitely appears to be a result of the bounding box, I modified the random_px_rect function and changed the last two lines from:
Y[rows, cols] = 1
return Y
to
try:
Y[rows, cols] = 1
except:
print("Error for Image size: {} bounding box: {:.0f}:{:.0f} , {:.0f}:{:.0f}".format(x.shape, y[0],y[1],y[2],y[3]))
return Y
and got the following results when it runs:
Error for Image size: (224, 298, 3) bounding box: 109:106 , 268:198
Error for Image size: (224, 298, 3) bounding box: 86:287 , 374:499
Error for Image size: (224, 298, 3) bounding box: 208:252 , 374:499
Error for Image size: (224, 282, 3) bounding box: 25:25 , 371:474
Error for Image size: (224, 298, 3) bounding box: 17:163 , 374:499
Error for Image size: (276, 224, 3) bounding box: 68:16 , 465:301
Error for Image size: (224, 298, 3) bounding box: 34:22 , 374:499
Error for Image size: (224, 298, 3) bounding box: 156:131 , 374:480
Error for Image size: (298, 224, 3) bounding box: 383:198 , 482:374
Error for Image size: (224, 298, 3) bounding box: 2:49 , 374:499
Error for Image size: (224, 277, 3) bounding box: 69:60 , 347:499
Error for Image size: (224, 231, 3) bounding box: 104:55 , 382:399
Error for Image size: (224, 298, 3) bounding box: 12:74 , 374:499
Error for Image size: (224, 291, 3) bounding box: 40:35 , 350:442
In the bounding box passed into the function, the bottom/right row exceeds the image rows…