def forward(self, first_frame: torch.Tensor, last_frame: torch.Tensor) -> list[dict]:
        """Perform forward-pass through region extractor.

        The forward pass consists of:
        1. Object detection on the last frame using Mask R-CNN
        2. Optional foreground detection by comparing first and last frames
        3. Post-processing to filter and refine detections

        Args:
            first_frame (torch.Tensor): Batch of input images of shape ``(N, C, H, W)``
                forming the first frames in the clip.
            last_frame (torch.Tensor): Batch of input images of shape ``(N, C, H, W)``
                forming the last frame in the clip.

        Returns:
            list[dict]: List of Mask R-CNN predictions for each image in the batch. Each
                dict contains:
                - boxes (torch.Tensor): Detected bounding boxes
                - labels (torch.Tensor): Class labels for each detection
                - scores (torch.Tensor): Confidence scores for each detection
                - masks (torch.Tensor): Instance segmentation masks
        """
        with torch.no_grad():
            regions = self.backbone(last_frame)

        if self.enable_foreground_detections:
            regions = self._add_foreground_boxes(
                regions=regions,
                first_frame=first_frame,
                last_frame=last_frame,
                kernel_size=self.foreground_kernel_size,
                binary_threshold=self.foreground_binary_threshold,
            )

        return self.post_process_bbox_detections(regions)
Perform forward-pass through region extractor.

        The forward pass consists of:
        1. Object detection on the last frame using Mask R-CNN
        2. Optional foreground detection by comparing first and last frames
        3. Post-processing to filter and refine detections

        Args:
            first_frame (torch.Tensor): Batch of input images of shape ``(N, C, H, W)``
                forming the first frames in the clip.
            last_frame (torch.Tensor): Batch of input images of shape ``(N, C, H, W)``
                forming the last frame in the clip.

        Returns:
            list[dict]: List of Mask R-CNN predictions for each image in the batch. Each
                dict contains:
                - boxes (torch.Tensor): Detected bounding boxes
                - labels (torch.Tensor): Class labels for each detection
                - scores (torch.Tensor): Confidence scores for each detection
                - masks (torch.Tensor): Instance segmentation masks
        
src/anomalib/models/video/ai_vad/regions.py