def generate_embedding(self, features: dict[str, torch.Tensor]) -> torch.Tensor:
        """Generate embedding from hierarchical feature map.

        This method combines features from multiple layers of the backbone network
        to create a rich embedding that captures both low-level and high-level
        image features.

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

        Returns:
            torch.Tensor: Embedding tensor combining features from all specified
                layers, with dimensions reduced according to ``n_features``.
        """
        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="nearest")
            embeddings = torch.cat((embeddings, layer_embedding), 1)

        # subsample embeddings
        idx = self.idx.to(embeddings.device)
        return torch.index_select(embeddings, 1, idx)
Generate embedding from hierarchical feature map.

        This method combines features from multiple layers of the backbone network
        to create a rich embedding that captures both low-level and high-level
        image features.

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

        Returns:
            torch.Tensor: Embedding tensor combining features from all specified
                layers, with dimensions reduced according to ``n_features``.
        
src/anomalib/models/image/padim/torch_model.py