def _sync_transform(self, img, mask):
    if (random.random() < 0.5):
        img = img.transpose(Image.FLIP_LEFT_RIGHT)
        mask = mask.transpose(Image.FLIP_LEFT_RIGHT)
    crop_size = self.crop_size
    (w, h) = img.size
    min_side = min(w, h)
    scale = np.random.uniform(0.5, 2.0)
    if ((min_side * scale) < 350):
        scale = ((350 * 1.0) / min_side)
    long_size = int((self.base_size * scale))
    if (h > w):
        oh = long_size
        ow = int(((((1.0 * w) * long_size) / h) + 0.5))
        short_size = ow
    else:
        ow = long_size
        oh = int(((((1.0 * h) * long_size) / w) + 0.5))
        short_size = oh
    img = img.resize((ow, oh), Image.BILINEAR)
    mask = mask.resize((ow, oh), Image.NEAREST)
    if (short_size < crop_size):
        padh = ((crop_size - oh) if (oh < crop_size) else 0)
        padw = ((crop_size - ow) if (ow < crop_size) else 0)
        img = ImageOps.expand(img, border=(0, 0, padw, padh), fill=0)
        mask = ImageOps.expand(mask, border=(0, 0, padw, padh), fill=0)
    (w, h) = img.size
    x1 = random.randint(0, (w - crop_size))
    y1 = random.randint(0, (h - crop_size))
    img = img.crop((x1, y1, (x1 + crop_size), (y1 + crop_size)))
    mask = mask.crop((x1, y1, (x1 + crop_size), (y1 + crop_size)))
    return (img, self._mask_transform(mask))
def _sync_transform(self, img, mask):
    if (random.random() < 0.5):
        img = img.transpose(Image.FLIP_LEFT_RIGHT)
        mask = mask.transpose(Image.FLIP_LEFT_RIGHT)
    crop_size = self.crop_size
    (w, h) = img.size
    min_side = min(w, h)
    scale = np.random.uniform(0.5, 2.0)
    if ((min_side * scale) < 350):
        scale = ((350 * 1.0) / min_side)
    long_size = int((self.base_size * scale))
    if (h > w):
        oh = long_size
        ow = int(((((1.0 * w) * long_size) / h) + 0.5))
        short_size = ow
    else:
        ow = long_size
        oh = int(((((1.0 * h) * long_size) / w) + 0.5))
        short_size = oh
    img = img.resize((ow, oh), Image.BILINEAR)
    mask = mask.resize((ow, oh), Image.NEAREST)
    if (short_size < crop_size):
        padh = ((crop_size - oh) if (oh < crop_size) else 0)
        padw = ((crop_size - ow) if (ow < crop_size) else 0)
        img = ImageOps.expand(img, border=(0, 0, padw, padh), fill=0)
        mask = ImageOps.expand(mask, border=(0, 0, padw, padh), fill=0)
    (w, h) = img.size
    x1 = random.randint(0, (w - crop_size))
    y1 = random.randint(0, (h - crop_size))
    img = img.crop((x1, y1, (x1 + crop_size), (y1 + crop_size)))
    mask = mask.crop((x1, y1, (x1 + crop_size), (y1 + crop_size)))
    return (img, self._mask_transform(mask))