def forward(
        self,
        recon_nq_hi: Tensor,
        recon_nq_lo: Tensor,
        qu_hi: Tensor,
        qu_lo: Tensor,
        input_image: Tensor,
        gen_img: Tensor,
        seg: Tensor,
        anomaly_mask: Tensor,
    ) -> Tensor:
        """Compute the combined loss over a batch.

        Args:
            recon_nq_hi (Tensor): Reconstructed non-quantized hi feature
            recon_nq_lo (Tensor): Reconstructed non-quantized lo feature
            qu_hi (Tensor): Non-defective quantized hi feature
            qu_lo (Tensor): Non-defective quantized lo feature
            input_image (Tensor): Original input image
            gen_img (Tensor): Object-specific decoded image
            seg (Tensor): Computed anomaly segmentation map
            anomaly_mask (Tensor): Ground truth anomaly mask

        Returns:
            Tensor: Total combined loss value

        Example:
            >>> loss_fn = DsrSecondStageLoss()
            >>> loss = loss_fn(
            ...     recon_nq_hi=torch.randn(32, 64, 32, 32),
            ...     recon_nq_lo=torch.randn(32, 64, 32, 32),
            ...     qu_hi=torch.randn(32, 64, 32, 32),
            ...     qu_lo=torch.randn(32, 64, 32, 32),
            ...     input_image=torch.randn(32, 3, 256, 256),
            ...     gen_img=torch.randn(32, 3, 256, 256),
            ...     seg=torch.randn(32, 2, 256, 256),
            ...     anomaly_mask=torch.randint(0, 2, (32, 1, 256, 256))
            ... )
        """
        l2_loss_hi_val = self.l2_loss(recon_nq_hi, qu_hi)
        l2_loss_lo_val = self.l2_loss(recon_nq_lo, qu_lo)
        l2_loss_img_val = self.l2_loss(input_image, gen_img) * 10
        focal_loss_val = self.focal_loss(seg, anomaly_mask.squeeze(1).long())
        return l2_loss_hi_val + l2_loss_lo_val + l2_loss_img_val + focal_loss_val
Compute the combined loss over a batch.

        Args:
            recon_nq_hi (Tensor): Reconstructed non-quantized hi feature
            recon_nq_lo (Tensor): Reconstructed non-quantized lo feature
            qu_hi (Tensor): Non-defective quantized hi feature
            qu_lo (Tensor): Non-defective quantized lo feature
            input_image (Tensor): Original input image
            gen_img (Tensor): Object-specific decoded image
            seg (Tensor): Computed anomaly segmentation map
            anomaly_mask (Tensor): Ground truth anomaly mask

        Returns:
            Tensor: Total combined loss value

        Example:
            >>> loss_fn = DsrSecondStageLoss()
            >>> loss = loss_fn(
            ...     recon_nq_hi=torch.randn(32, 64, 32, 32),
            ...     recon_nq_lo=torch.randn(32, 64, 32, 32),
            ...     qu_hi=torch.randn(32, 64, 32, 32),
            ...     qu_lo=torch.randn(32, 64, 32, 32),
            ...     input_image=torch.randn(32, 3, 256, 256),
            ...     gen_img=torch.randn(32, 3, 256, 256),
            ...     seg=torch.randn(32, 2, 256, 256),
            ...     anomaly_mask=torch.randint(0, 2, (32, 1, 256, 256))
            ... )
        
src/anomalib/models/image/dsr/loss.py