class_docstr: Resize and Keep Aspect Ratio
      
class_docstr_tok: ["Resize","and","Keep","Aspect","Ratio"]
docstr: Get parameters
          
docstr_tok: ["Get","parameters"]
code: def get_params(
      img,
      target_size,
      longest,
      random_scale_prob=0.0,
      random_scale_range=(1.0, 1.33),
      random_scale_area=False,
      random_aspect_prob=0.0,
      random_aspect_range=(0.9, 1.11),
  ):
      """Get parameters"""
      img_h, img_w = img_size = F.get_dimensions(img)[1:]
      target_h, target_w = target_size
      ratio_h = img_h / target_h
      ratio_w = img_w / target_w
      ratio = max(ratio_h, ratio_w) * longest + min(
          ratio_h, ratio_w
      ) * (1.0 - longest)
  
      if random_scale_prob > 0 and random.random() < random_scale_prob:
          ratio_factor = random.uniform(
              random_scale_range[0], random_scale_range[1]
          )
          if random_scale_area:
              # make ratio factor equivalent to RRC area crop where < 1.0 = area zoom,
              # otherwise like affine scale where < 1.0 = linear zoom out
              ratio_factor = 1.0 / math.sqrt(ratio_factor)
          ratio_factor = (ratio_factor, ratio_factor)
      else:
          ratio_factor = (1.0, 1.0)
  
      if (
          random_aspect_prob > 0
          and random.random() < random_aspect_prob
      ):
          log_aspect = (
              math.log(random_aspect_range[0]),
              math.log(random_aspect_range[1]),
          )
          aspect_factor = math.exp(random.uniform(*log_aspect))
          aspect_factor = math.sqrt(aspect_factor)
          # currently applying random aspect adjustment equally to both dims,
          # could change to keep output sizes above their target where possible
          ratio_factor = (
              ratio_factor[0] / aspect_factor,
              ratio_factor[1] * aspect_factor,
          )
  
      size = [
          round(x * f / ratio) for x, f in zip(img_size, ratio_factor)
      ]
      return size
  
imports: import math
  import numbers
  import random
  import warnings
  from typing import List, Sequence, Tuple, Union
  import torch
  import torchvision.transforms.functional
  from PIL import Image
  import numpy
label_desc: Use image node_id 2 for calling the ResizeKeepRatio obj's underlying member method code with example usage: obj.get_params(img, target_size, longest, random_scale_prob, random_scale_range, random_scale_area, random_aspect_prob, random_aspect_range) and returns: size