class_docstr: Extract features from a CNN.
  
  Args:
      backbone (nn.Module): The backbone to which the feature extraction hooks are attached.
      layers (Iterable[str]): List of layer names of the backbone to which the hooks are attached.
      pre_trained (bool): Whether to use a pre-trained backbone. Defaults to True.
      requires_grad (bool): Whether to require gradients for the backbone. Defaults to False.
          Models like ``stfpm`` use the feature extractor model as a trainable network. In such cases gradient
          computation is required.
  
  Example:
      >>> import torch
      >>> from anomalib.models.components.feature_extractors import TimmFeatureExtractor
  
      >>> model = TimmFeatureExtractor(model="resnet18", layers=['layer1', 'layer2', 'layer3'])
      >>> input = torch.rand((32, 3, 256, 256))
      >>> features = model(input)
  
      >>> [layer for layer in features.keys()]
          ['layer1', 'layer2', 'layer3']
      >>> [feature.shape for feature in features.values()]
          [torch.Size([32, 64, 64, 64]), torch.Size([32, 128, 32, 32]), torch.Size([32, 256, 16, 16])]
docstr: Forward-pass input tensor into the CNN.
  
  Args:
      inputs (Tensor): Input tensor
  
  Returns:
      Feature map extracted from the CNN
docstr_tok: ["Forward-pass","input","tensor","into","the","CNN",".","Args",":","inputs","(","Tensor",")",":","Input","tensor","Returns",":","Feature","map","extracted","from","the","CNN"]
code: def forward(self, inputs: Tensor) -> dict[str, Tensor]:
      """Forward-pass input tensor into the CNN.
  
      Args:
          inputs (Tensor): Input tensor
  
      Returns:
          Feature map extracted from the CNN
      """
      if self.requires_grad:
          features = dict(
              zip(self.layers, self.feature_extractor(inputs))
          )
      else:
          self.feature_extractor.eval()
          with torch.no_grad():
              features = dict(
                  zip(self.layers, self.feature_extractor(inputs))
              )
      return features
  
file_path: anomalib/src/anomalib/models/components/feature_extractors/timm.py
imports: from __future__ import annotations
  import logging
  import warnings
  import timm
  import torch
  from torch import Tensor, nn
label_desc: Use image node_id 3 for calling the TimmFeatureExtractor obj's underlying member method code with example usage: obj.forward(inputs) and returns: features