code: def roi_align(
      input,
      boxes,
      output_size,
      spatial_scale=1.0,
      sampling_ratio=-1,
      aligned=False,
  ):
      pooled_height, pooled_width = (
          (output_size, output_size)
          if isinstance(output_size, int)
          else output_size
      )
  
      if not isinstance(boxes, ivy.Array):
          boxes = _convert_boxes_to_roi_format(boxes)
      orig_dtype = input.dtype
  
      _, _, height, width = input.shape
  
      ph = ivy.arange(pooled_height, device=input.device)  # [PH]
      pw = ivy.arange(pooled_width, device=input.device)  # [PW]
  
      # input: [N, C, H, W]
      # boxes: [K, 5]
  
      roi_batch_ind = boxes[:, 0].astype(ivy.int32)  # [K]
      offset = 0.5 if aligned else 0.0
      roi_start_w = boxes[:, 1] * spatial_scale - offset  # [K]
      roi_start_h = boxes[:, 2] * spatial_scale - offset  # [K]
      roi_end_w = boxes[:, 3] * spatial_scale - offset  # [K]
      roi_end_h = boxes[:, 4] * spatial_scale - offset  # [K]
  
      roi_width = roi_end_w - roi_start_w  # [K]
      roi_height = roi_end_h - roi_start_h  # [K]
      if not aligned:
          roi_width = ivy.clip(roi_width, 1.0, None)  # [K]
          roi_height = ivy.clip(roi_height, 1.0, None)  # [K]
  
      bin_size_h = roi_height / pooled_height  # [K]
      bin_size_w = roi_width / pooled_width  # [K]
  
      exact_sampling = sampling_ratio > 0
  
      roi_bin_grid_h = (
          sampling_ratio
          if exact_sampling
          else ivy.ceil(roi_height / pooled_height)
      )  # scalar or [K]
      roi_bin_grid_w = (
          sampling_ratio
          if exact_sampling
          else ivy.ceil(roi_width / pooled_width)
      )  # scalar or [K]
      """Iy, ix = dims(2)"""
  
      if exact_sampling:
          count = max(roi_bin_grid_h * roi_bin_grid_w, 1)  # scalar
          iy = ivy.arange(roi_bin_grid_h, device=input.device)  # [IY]
          ix = ivy.arange(roi_bin_grid_w, device=input.device)  # [IX]
          ymask = None
          xmask = None
      else:
          count = ivy.clip(
              roi_bin_grid_h * roi_bin_grid_w, 1, None
          )  # [K]
          iy = ivy.arange(height, device=input.device)  # [IY]
          ix = ivy.arange(width, device=input.device)  # [IX]
          ymask = iy[None, :] < roi_bin_grid_h[:, None]  # [K, IY]
          xmask = ix[None, :] < roi_bin_grid_w[:, None]  # [K, IX]
  
      def from_K(t):
          return t[:, None, None]
  
      y = (
          from_K(roi_start_h)
          + ph[None, :, None] * from_K(bin_size_h)
          + (iy[None, None, :] + 0.5).astype(input.dtype)
          * from_K(bin_size_h / roi_bin_grid_h)
      )  # [K, PH, IY]
      x = (
          from_K(roi_start_w)
          + pw[None, :, None] * from_K(bin_size_w)
          + (ix[None, None, :] + 0.5).astype(input.dtype)
          * from_K(bin_size_w / roi_bin_grid_w)
      )  # [K, PW, IX]
      val = _bilinear_interpolate(
          input, roi_batch_ind, y, x, ymask, xmask
      )  # [K, C, PH, PW, IY, IX]
  
      # Mask out samples that weren't actually adaptively needed
      if not exact_sampling:
          val = ivy.where(ymask[:, None, None, None, :, None], val, 0)
          val = ivy.where(xmask[:, None, None, None, None, :], val, 0)
  
      output = val.sum(axis=(-1, -2))  # remove IY, IX ~> [K, C, PH, PW]
      if isinstance(count, ivy.Array):
          output /= count[:, None, None, None]
      else:
          output /= count
  
      output = output.astype(orig_dtype)
  
      return output
  
imports: from typing import Optional, Tuple, Union, Sequence
  import ivy
  from ivy.utils.backend import current_backend
  from ivy.func_wrapper import handle_array_function, handle_partial_mixed_function, inputs_to_ivy_arrays, to_native_arrays_and_back, inputs_to_native_shapes, handle_out_argument, handle_nestable, handle_array_like_without_promotion, handle_device, handle_backend_invalid
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 35 for calling a global function with example usage: roi_align(input, boxes, output_size, spatial_scale, sampling_ratio, aligned) and returns: output, t