    def apply_transform(self, img):
        """
        Resize the image while keeping the aspect ratio unchanged.
        It attempts to scale the shorter edge to the given `short_edge_length`,
        as long as the longer edge does not exceed `max_size`.
        If `max_size` is reached, then downscale so that the longer edge does not exceed max_size.
        """
        h, w = img.shape[:2]
        new_h, new_w = Predictor.get_output_shape(h, w, self.min_size, self.max_size)
        if len(img.shape) > 2 and img.shape[2] == 1:
            pil_image = Image.fromarray(img[:, :, 0], mode="L")
        else:
            pil_image = Image.fromarray(img)
        pil_image = pil_image.resize((new_w, new_h), self.interp_method)
        ret = np.asarray(pil_image)
        if len(img.shape) > 2 and img.shape[2] == 1:
            ret = np.expand_dims(ret, -1)
        return ret
Resize the image while keeping the aspect ratio unchanged.
It attempts to scale the shorter edge to the given `short_edge_length`,
as long as the longer edge does not exceed `max_size`.
If `max_size` is reached, then downscale so that the longer edge does not exceed max_size.
examples/02_detectron2/predictor/predictor.py