Solved by LeanderK in post #2 
              
              
                Ok, I think I’ve solved it: 
#get batched bounds for pytorch
def get_bounds_t(img):
    b,h,w = img.shape[:3]
    rows = torch.any(img, axis=2)
    cols = torch.any(img, axis=1)
    rmins = torch.argmax(rows.float(), dim=1)
    rmaxs = h - torch.argmax(rows.float().flip(dims=[1]), dim=1)
    cmins =…