def generate_embedding(self, features: dict[str, torch.Tensor]) -> torch.Tensor:
        """Generate embedding by concatenating multi-scale feature maps.

        Combines feature maps from different CNN layers by upsampling them to a
        common size and concatenating along the channel dimension.

        Args:
            features (dict[str, torch.Tensor]): Dictionary mapping layer names to
                feature tensors extracted from the backbone CNN.

        Returns:
            torch.Tensor: Concatenated feature embedding of shape
                ``(batch_size, num_features, height, width)``.

        Example:
            >>> features = {
            ...     "layer1": torch.randn(32, 64, 56, 56),
            ...     "layer2": torch.randn(32, 128, 28, 28)
            ... }
            >>> embedding = model.generate_embedding(features)
            >>> embedding.shape
            torch.Size([32, 192, 56, 56])
        """
        embeddings = features[self.layers[0]]
        for layer in self.layers[1:]:
            layer_embedding = features[layer]
            layer_embedding = F.interpolate(layer_embedding, size=embeddings.shape[-2:], mode="bilinear")
            embeddings = torch.cat((embeddings, layer_embedding), 1)

        return embeddings
Generate embedding by concatenating multi-scale feature maps.

        Combines feature maps from different CNN layers by upsampling them to a
        common size and concatenating along the channel dimension.

        Args:
            features (dict[str, torch.Tensor]): Dictionary mapping layer names to
                feature tensors extracted from the backbone CNN.

        Returns:
            torch.Tensor: Concatenated feature embedding of shape
                ``(batch_size, num_features, height, width)``.

        Example:
            >>> features = {
            ...     "layer1": torch.randn(32, 64, 56, 56),
            ...     "layer2": torch.randn(32, 128, 28, 28)
            ... }
            >>> embedding = model.generate_embedding(features)
            >>> embedding.shape
            torch.Size([32, 192, 56, 56])
        
src/anomalib/models/image/patchcore/torch_model.py