def get_feature_extractor(backbone: str, return_nodes: list[str]) -> GraphModule:
    """Create a feature extractor from a backbone CNN.

    Args:
        backbone (str): Name of the backbone CNN network.
        return_nodes (list[str]): List of layer names to extract features from.

    Raises:
        NotImplementedError: When ``backbone`` is efficientnet_b5.
        ValueError: When ``backbone`` is not supported.

    Returns:
        GraphModule: Feature extractor module.

    Example:
        >>> nodes = ["layer1", "layer2", "layer3"]
        >>> extractor = get_feature_extractor("resnet18", nodes)
        >>> x = torch.randn(1, 3, 224, 224)
        >>> features = extractor(x)
    """
    model = getattr(torchvision.models, backbone)(pretrained=True)
    feature_extractor = create_feature_extractor(model=model, return_nodes=return_nodes)
    feature_extractor.eval()

    return feature_extractor
Create a feature extractor from a backbone CNN.

    Args:
        backbone (str): Name of the backbone CNN network.
        return_nodes (list[str]): List of layer names to extract features from.

    Raises:
        NotImplementedError: When ``backbone`` is efficientnet_b5.
        ValueError: When ``backbone`` is not supported.

    Returns:
        GraphModule: Feature extractor module.

    Example:
        >>> nodes = ["layer1", "layer2", "layer3"]
        >>> extractor = get_feature_extractor("resnet18", nodes)
        >>> x = torch.randn(1, 3, 224, 224)
        >>> features = extractor(x)
    
src/anomalib/models/image/cfa/torch_model.py