def get_features(self, batch: torch.Tensor) -> torch.Tensor:
        """Extract features from the pre-trained backbone network.

        Args:
            batch (torch.Tensor): Batch of input images with shape
                ``(N, C, H, W)``.

        Returns:
            torch.Tensor: Concatenated features from specified layers, flattened
                to shape ``(N, D)`` where ``D`` is the total feature dimension.

        Example:
            >>> batch = torch.randn(32, 3, 224, 224)
            >>> features = model.get_features(batch)
            >>> features.shape
            torch.Size([32, 512])  # Depends on backbone and layers
        """
        self.feature_extractor.eval()
        layer_outputs = self.feature_extractor(batch)
        for layer in layer_outputs:
            batch_size = len(layer_outputs[layer])
            layer_outputs[layer] = F.adaptive_avg_pool2d(input=layer_outputs[layer], output_size=(1, 1))
            layer_outputs[layer] = layer_outputs[layer].view(batch_size, -1)
        return torch.cat(list(layer_outputs.values())).detach()
Extract features from the pre-trained backbone network.

        Args:
            batch (torch.Tensor): Batch of input images with shape
                ``(N, C, H, W)``.

        Returns:
            torch.Tensor: Concatenated features from specified layers, flattened
                to shape ``(N, D)`` where ``D`` is the total feature dimension.

        Example:
            >>> batch = torch.randn(32, 3, 224, 224)
            >>> features = model.get_features(batch)
            >>> features.shape
            torch.Size([32, 512])  # Depends on backbone and layers
        
src/anomalib/models/image/dfkde/torch_model.py