class_docstr: Region extractor for AI-VAD.
  
  Args:
      box_score_thresh (float): Confidence threshold for bounding box predictions.
      persons_only (bool): When enabled, only regions labeled as person are included.
      min_bbox_area (int): Minimum bounding box area. Regions with a surface area lower than this value are excluded.
      max_bbox_overlap (float): Maximum allowed overlap between bounding boxes.
      enable_foreground_detections (bool): Add additional foreground detections based on pixel difference between
          consecutive frames.
      foreground_kernel_size (int): Gaussian kernel size used in foreground detection.
      foreground_binary_threshold (int): Value between 0 and 255 which acts as binary threshold in foreground
          detection.
class_docstr_tok: ["Region","extractor","for","AI-VAD",".","Args",":","box_score_thresh","(","float",")",":","Confidence","threshold","for","bounding","box","predictions",".","persons_only","(","bool",")",":","When","enabled",",","only","regions","labeled","as","person","are","included",".","min_bbox_area","(","int",")",":","Minimum","bounding","box","area",".","Regions","with","a","surface","area","lower","than","this","value","are","excluded",".","max_bbox_overlap","(","float",")",":","Maximum","allowed","overlap","between","bounding","boxes",".","enable_foreground_detections","(","bool",")",":","Add","additional","foreground","detections","based","on","pixel","difference","between","consecutive","frames",".","foreground_kernel_size","(","int",")",":","Gaussian","kernel","size","used","in","foreground","detection",".","foreground_binary_threshold","(","int",")",":","Value","between","0","and","255","which","acts","as","binary","threshold","in","foreground","detection","."]
docstr: Forward pass through region extractor.
  
  Args:
      first_frame (Tensor): Batch of input images of shape (N, C, H, W) forming the first frames in the clip
      last_frame (Tensor): Batch of input images of shape (N, C, H, W) forming the last frame in the clip
  Returns:
      list[dict]: List of Mask RCNN predictions for each image in the batch.
docstr_tok: ["Forward","pass","through","region","extractor",".","Args",":","first_frame","(","Tensor",")",":","Batch","of","input","images","of","shape","(","N",",","C",",","H",",","W",")","forming","the","first","frames","in","the","clip","last_frame","(","Tensor",")",":","Batch","of","input","images","of","shape","(","N",",","C",",","H",",","W",")","forming","the","last","frame","in","the","clip","Returns",":","list","[","dict","]",":","List","of","Mask","RCNN","predictions","for","each","image","in","the","batch","."]
code: def forward(
      self, first_frame: Tensor, last_frame: Tensor
  ) -> list[dict]:
      """Forward pass through region extractor.
  
      Args:
          first_frame (Tensor): Batch of input images of shape (N, C, H, W) forming the first frames in the clip
          last_frame (Tensor): Batch of input images of shape (N, C, H, W) forming the last frame in the clip
      Returns:
          list[dict]: List of Mask RCNN predictions for each image in the batch.
      """
      with torch.no_grad():
          regions = self.backbone(last_frame)
  
      if self.enable_foreground_detections:
          regions = self.add_foreground_boxes(
              regions,
              first_frame,
              last_frame,
              self.foreground_kernel_size,
              self.foreground_binary_threshold,
          )
  
      regions = self.post_process_bbox_detections(regions)
  
      return regions
  
file_path: anomalib/src/anomalib/models/ai_vad/regions.py
imports: from __future__ import annotations
  import torch
  from torch import Tensor, nn
  from torchvision.models.detection import MaskRCNN_ResNet50_FPN_V2_Weights, maskrcnn_resnet50_fpn_v2
  from torchvision.ops import box_area, clip_boxes_to_image
  from torchvision.transforms.functional import gaussian_blur, rgb_to_grayscale
  from anomalib.data.utils.boxes import boxes_to_masks, masks_to_boxes
label_desc: Use image node_id 2 for calling the RegionExtractor obj's underlying member method code with example usage: obj.forward(first_frame, last_frame) and returns: regions