def compute_layer_map(
        teacher_features: torch.Tensor,
        student_features: torch.Tensor,
        image_size: tuple[int, int] | torch.Size,
    ) -> torch.Tensor:
        """Compute anomaly map for a single feature layer.

        The layer map is computed by:
        1. Normalizing teacher and student features
        2. Computing L2 distance between normalized features
        3. Upscaling the distance map to original image size

        Args:
            teacher_features (torch.Tensor): Features from teacher network with
                shape ``(B, C, H, W)``
            student_features (torch.Tensor): Features from student network with
                matching shape
            image_size (tuple[int, int] | torch.Size): Target size for upscaling
                in format ``(H, W)``

        Returns:
            torch.Tensor: Anomaly scores for the layer, upscaled to
                ``image_size``
        """
        norm_teacher_features = F.normalize(teacher_features)
        norm_student_features = F.normalize(student_features)

        layer_map = 0.5 * torch.norm(norm_teacher_features - norm_student_features, p=2, dim=-3, keepdim=True) ** 2
        return F.interpolate(layer_map, size=image_size, align_corners=False, mode="bilinear")
Compute anomaly map for a single feature layer.

        The layer map is computed by:
        1. Normalizing teacher and student features
        2. Computing L2 distance between normalized features
        3. Upscaling the distance map to original image size

        Args:
            teacher_features (torch.Tensor): Features from teacher network with
                shape ``(B, C, H, W)``
            student_features (torch.Tensor): Features from student network with
                matching shape
            image_size (tuple[int, int] | torch.Size): Target size for upscaling
                in format ``(H, W)``

        Returns:
            torch.Tensor: Anomaly scores for the layer, upscaled to
                ``image_size``
        
src/anomalib/models/image/stfpm/anomaly_map.py