code: def _copy_paste(
      self,
      image: Union[torch.Tensor, tv_tensors.Image],
      target: Dict[str, Any],
      paste_image: Union[torch.Tensor, tv_tensors.Image],
      paste_target: Dict[str, Any],
      random_selection: torch.Tensor,
      blending: bool,
      resize_interpolation: F.InterpolationMode,
      antialias: Optional[bool],
  ) -> Tuple[torch.Tensor, Dict[str, Any]]:
      paste_masks = tv_tensors.wrap(
          paste_target["masks"][random_selection],
          like=paste_target["masks"],
      )
      paste_boxes = tv_tensors.wrap(
          paste_target["boxes"][random_selection],
          like=paste_target["boxes"],
      )
      paste_labels = tv_tensors.wrap(
          paste_target["labels"][random_selection],
          like=paste_target["labels"],
      )
  
      masks = target["masks"]
  
      # We resize source and paste data if they have different sizes
      # This is something different to TF implementation we introduced here as
      # originally the algorithm works on equal-sized data
      # (for example, coming from LSJ data augmentations)
      size1 = cast(List[int], image.shape[-2:])
      size2 = paste_image.shape[-2:]
      if size1 != size2:
          paste_image = F.resize(
              paste_image,
              size=size1,
              interpolation=resize_interpolation,
              antialias=antialias,
          )
          paste_masks = F.resize(paste_masks, size=size1)
          paste_boxes = F.resize(paste_boxes, size=size1)
  
      paste_alpha_mask = paste_masks.sum(dim=0) > 0
  
      if blending:
          paste_alpha_mask = F.gaussian_blur(
              paste_alpha_mask.unsqueeze(0),
              kernel_size=[5, 5],
              sigma=[2.0],
          )
  
      inverse_paste_alpha_mask = paste_alpha_mask.logical_not()
      # Copy-paste images:
      image = image.mul(inverse_paste_alpha_mask).add_(
          paste_image.mul(paste_alpha_mask)
      )
  
      # Copy-paste masks:
      masks = masks * inverse_paste_alpha_mask
      non_all_zero_masks = masks.sum((-1, -2)) > 0
      masks = masks[non_all_zero_masks]
  
      # Do a shallow copy of the target dict
      out_target = {k: v for k, v in target.items()}
  
      out_target["masks"] = torch.cat([masks, paste_masks])
  
      # Copy-paste boxes and labels
      bbox_format = target["boxes"].format
      xyxy_boxes = masks_to_boxes(masks)
      # masks_to_boxes produces bboxes with x2y2 inclusive but x2y2 should be exclusive
      # we need to add +1 to x2y2.
      # There is a similar +1 in other reference implementations:
      # https://github.com/pytorch/vision/blob/b6feccbc4387766b76a3e22b13815dbbbfa87c0f/torchvision/models/detection/roi_heads.py#L418-L422
      xyxy_boxes[:, 2:] += 1
      boxes = F.convert_bounding_box_format(
          xyxy_boxes,
          old_format=tv_tensors.BoundingBoxFormat.XYXY,
          new_format=bbox_format,
          inplace=True,
      )
      out_target["boxes"] = torch.cat([boxes, paste_boxes])
  
      labels = target["labels"][non_all_zero_masks]
      out_target["labels"] = torch.cat([labels, paste_labels])
  
      # Check for degenerated boxes and remove them
      boxes = F.convert_bounding_box_format(
          out_target["boxes"],
          old_format=bbox_format,
          new_format=tv_tensors.BoundingBoxFormat.XYXY,
      )
      degenerate_boxes = boxes[:, 2:] <= boxes[:, :2]
      if degenerate_boxes.any():
          valid_targets = ~degenerate_boxes.any(dim=1)
  
          out_target["boxes"] = boxes[valid_targets]
          out_target["masks"] = out_target["masks"][valid_targets]
          out_target["labels"] = out_target["labels"][valid_targets]
  
      return image, out_target
  
file_path: vision/torchvision/prototype/transforms/_augment.py
imports: from typing import Any, cast, Dict, List, Optional, Tuple, Union
  import PIL.Image
  import torch
  from torch.utils._pytree import tree_flatten, tree_unflatten
  from torchvision import tv_tensors
  from torchvision.ops import masks_to_boxes
  from torchvision.prototype import tv_tensors
  from torchvision.transforms.v2 import functional, InterpolationMode, Transform
  from torchvision.transforms.v2._utils import is_pure_tensor
  from torchvision.transforms.v2.functional._geometry import _check_interpolation
label_desc: Use image node_id 2 for calling the SimpleCopyPaste obj's underlying member method code with example usage: obj._copy_paste(image, target, paste_image, paste_target, random_selection, blending, resize_interpolation, antialias) and returns: image,  out_target