class_docstr: Randomly flip and crop an image.
  
  A PyTorch module that applies random cropping, horizontal and vertical flipping to an image,
  and returns the transformed image and a grid tensor used to map the image back to the
  original image space in an NxN grid.
  
  Args:
      grid_size:
          The number of grid cells in the output grid tensor.
      crop_size:
          The size (in pixels) of the random crops.
      crop_min_scale:
          The minimum scale factor for random resized crops.
      crop_max_scale:
          The maximum scale factor for random resized crops.
      hf_prob:
          The probability of applying horizontal flipping to the image.
      normalize:
          A dictionary containing the mean and std values for normalizing the image.
class_docstr_tok: ["Randomly","flip","and","crop","an","image",".","A","PyTorch","module","that","applies","random","cropping",",","horizontal","and","vertical","flipping","to","an","image",",","and","returns","the","transformed","image","and","a","grid","tensor","used","to","map","the","image","back","to","the","original","image","space","in","an","NxN","grid",".","Args",":","grid_size",":","The","number","of","grid","cells","in","the","output","grid","tensor",".","crop_size",":","The","size","(","in","pixels",")","of","the","random","crops",".","crop_min_scale",":","The","minimum","scale","factor","for","random","resized","crops",".","crop_max_scale",":","The","maximum","scale","factor","for","random","resized","crops",".","hf_prob",":","The","probability","of","applying","horizontal","flipping","to","the","image",".","normalize",":","A","dictionary","containing","the","mean","and","std","values","for","normalizing","the","image","."]
docstr: Create grid from location object.
  
  Create a grid tensor with grid_size rows and grid_size columns, where each cell represents a region of
  the original image. The grid is used to map the cropped and transformed image back to the
  original image space.
  
  Args:
      location: An instance of the Location class, containing the location and size of the
          transformed image in the original image space.
  
  Returns:
      A grid tensor of shape (grid_size, grid_size, 2), where the last dimension represents the (x, y) coordinate
      of the center of each cell in the original image space.
docstr_tok: ["Create","grid","from","location","object",".","Create","a","grid","tensor","with","grid_size","rows","and","grid_size","columns",",","where","each","cell","represents","a","region","of","the","original","image",".","The","grid","is","used","to","map","the","cropped","and","transformed","image","back","to","the","original","image","space",".","Args",":","location",":","An","instance","of","the","Location","class",",","containing","the","location","and","size","of","the","transformed","image","in","the","original","image","space",".","Returns",":","A","grid","tensor","of","shape","(","grid_size",",","grid_size",",","2",")",",","where","the","last","dimension","represents","the","(","x",",","y",")","coordinate","of","the","center","of","each","cell","in","the","original","image","space","."]
code: def location_to_NxN_grid(self, location: Location) -> torch.Tensor:
      """Create grid from location object.
  
      Create a grid tensor with grid_size rows and grid_size columns, where each cell represents a region of
      the original image. The grid is used to map the cropped and transformed image back to the
      original image space.
  
      Args:
          location: An instance of the Location class, containing the location and size of the
              transformed image in the original image space.
  
      Returns:
          A grid tensor of shape (grid_size, grid_size, 2), where the last dimension represents the (x, y) coordinate
          of the center of each cell in the original image space.
      """
  
      cell_width = location.width / self.grid_size
      cell_height = location.height / self.grid_size
      x = torch.linspace(
          location.left, location.left + location.width, self.grid_size
      ) + (cell_width / 2)
      y = torch.linspace(
          location.top, location.top + location.height, self.grid_size
      ) + (cell_height / 2)
      if location.horizontal_flip:
          x = torch.flip(x, dims=[0])
      if location.vertical_flip:
          y = torch.flip(y, dims=[0])
      grid_x, grid_y = torch.meshgrid(x, y, indexing="xy")
      return torch.stack([grid_x, grid_y], dim=-1)
  
imports: from dataclasses import dataclass
  from typing import Tuple
  import torch
  import torchvision.transforms
  import torchvision.transforms.functional
  from PIL import Image
  from torch import nn
label_desc: Use image node_id 3 for calling the RandomResizedCropAndFlip obj's underlying member method code with example usage: obj.location_to_NxN_grid(location) and returns: torch