code: def forward(self, img1, img2, flow, valid_flow_mask):
      # randomly sample scale
      h, w = img1.shape[-2:]
      # Note: in original code, they use + 1 instead of + 8 for sparse datasets (e.g. Kitti)
      # It shouldn't matter much
      min_scale = max(
          (self.crop_size[0] + 8) / h, (self.crop_size[1] + 8) / w
      )
  
      scale = (
          2
          ** torch.empty(1, dtype=torch.float32)
          .uniform_(self.min_scale, self.max_scale)
          .item()
      )
      scale_x = scale
      scale_y = scale
      if torch.rand(1) < self.stretch_prob:
          scale_x *= (
              2
              ** torch.empty(1, dtype=torch.float32)
              .uniform_(-self.max_stretch, self.max_stretch)
              .item()
          )
          scale_y *= (
              2
              ** torch.empty(1, dtype=torch.float32)
              .uniform_(-self.max_stretch, self.max_stretch)
              .item()
          )
  
      scale_x = max(scale_x, min_scale)
      scale_y = max(scale_y, min_scale)
  
      new_h, new_w = round(h * scale_y), round(w * scale_x)
  
      if torch.rand(1).item() < self.resize_prob:
          # rescale the images
          # We hard-code antialias=False to preserve results after we changed
          # its default from None to True (see
          # https://github.com/pytorch/vision/pull/7160)
          # TODO: we could re-train the OF models with antialias=True?
          img1 = F.resize(img1, size=(new_h, new_w), antialias=False)
          img2 = F.resize(img2, size=(new_h, new_w), antialias=False)
          if valid_flow_mask is None:
              flow = F.resize(flow, size=(new_h, new_w))
              flow = (
                  flow * torch.tensor([scale_x, scale_y])[:, None, None]
              )
          else:
              flow, valid_flow_mask = self._resize_sparse_flow(
                  flow,
                  valid_flow_mask,
                  scale_x=scale_x,
                  scale_y=scale_y,
              )
  
      # Note: For sparse datasets (Kitti), the original code uses a "margin"
      # See e.g. https://github.com/princeton-vl/RAFT/blob/master/core/utils/augmentor.py#L220:L220
      # We don't, not sure if it matters much
      y0 = torch.randint(
          0, img1.shape[1] - self.crop_size[0], size=(1,)
      ).item()
      x0 = torch.randint(
          0, img1.shape[2] - self.crop_size[1], size=(1,)
      ).item()
  
      img1 = F.crop(img1, y0, x0, self.crop_size[0], self.crop_size[1])
      img2 = F.crop(img2, y0, x0, self.crop_size[0], self.crop_size[1])
      flow = F.crop(flow, y0, x0, self.crop_size[0], self.crop_size[1])
      if valid_flow_mask is not None:
          valid_flow_mask = F.crop(
              valid_flow_mask,
              y0,
              x0,
              self.crop_size[0],
              self.crop_size[1],
          )
  
      return img1, img2, flow, valid_flow_mask
  
imports: import torch
  import torchvision.transforms
  import torchvision.transforms.functional
label_desc: Use image node_id 2 for calling the RandomResizeAndCrop obj's underlying member method code with example usage: obj.forward(img1, img2, flow, valid_flow_mask) and returns: img1,  img2,  flow,  valid_flow_mask