docstr: Resize the image numpy.
          
docstr_tok: ["Resize","the","image","numpy","."]
code: def apply(self, sample, context=None):
      """Resize the image numpy."""
      im = sample["image"]
      if not isinstance(im, np.ndarray):
          raise TypeError("{}: image type is not numpy.".format(self))
      if len(im.shape) != 3:
          raise ImageError(
              "{}: image is not 3-dimensional.".format(self)
          )
  
      # apply image
      im_shape = im.shape
      if self.keep_ratio:
          im_size_min = np.min(im_shape[0:2])
          im_size_max = np.max(im_shape[0:2])
  
          target_size_min = np.min(self.target_size)
          target_size_max = np.max(self.target_size)
  
          im_scale = min(
              target_size_min / im_size_min,
              target_size_max / im_size_max,
          )
  
          resize_h = im_scale * float(im_shape[0])
          resize_w = im_scale * float(im_shape[1])
  
          im_scale_x = im_scale
          im_scale_y = im_scale
      else:
          resize_h, resize_w = self.target_size
          im_scale_y = resize_h / im_shape[0]
          im_scale_x = resize_w / im_shape[1]
  
      im = self.apply_image(sample["image"], [im_scale_x, im_scale_y])
      sample["image"] = im.astype(np.float32)
      sample["im_shape"] = np.asarray(
          [resize_h, resize_w], dtype=np.float32
      )
      if "scale_factor" in sample:
          scale_factor = sample["scale_factor"]
          sample["scale_factor"] = np.asarray(
              [
                  scale_factor[0] * im_scale_y,
                  scale_factor[1] * im_scale_x,
              ],
              dtype=np.float32,
          )
      else:
          sample["scale_factor"] = np.asarray(
              [im_scale_y, im_scale_x], dtype=np.float32
          )
  
      # apply bbox
      if "gt_bbox" in sample and len(sample["gt_bbox"]) > 0:
          sample["gt_bbox"] = self.apply_pts(
              sample["gt_bbox"],
              [im_scale_x, im_scale_y],
              [resize_w, resize_h],
          )
  
      # apply polygon
      if "gt_poly" in sample and len(sample["gt_poly"]) > 0:
          sample["gt_poly"] = self.apply_pts(
              sample["gt_poly"],
              [im_scale_x, im_scale_y],
              [resize_w, resize_h],
          )
  
      return sample
  
imports: from __future__ import absolute_import
  from __future__ import print_function
  from __future__ import division
  from numbers import Number, Integral
  import cv2
  import numpy
  import math
  import copy
  from .operators import register_op, BaseOperator
  from ppdet.modeling.rbox_utils import poly2rbox_le135_np, poly2rbox_oc_np, rbox2poly_np
  from ppdet.utils.logger import setup_logger
  from ppdet.utils.compact import imagedraw_textsize_c
label_desc: Use image node_id 4 for calling the RResize obj's underlying member method code with example usage: obj.apply(sample, context) and returns: sample