Skip to main content

Overview

PatchCore supports a wide range of pretrained CNN and Transformer backbone architectures for feature extraction. All backbones are pretrained on ImageNet and can be combined in ensembles for improved performance.

Selecting a Backbone

Specify a backbone using the -b or --backbone flag:
For ensemble models, specify multiple backbones:

Available Backbones

All 40+ supported architectures are defined in src/patchcore/backbones.py.

ResNet Family

Standard ResNet architectures from torchvision and timm. Common Feature Layers: layer1, layer2, layer3, layer4

Wide ResNet

Recommended for baseline models - excellent balance of performance and efficiency. Feature Layers: layer1, layer2, layer3, layer4 Best Practice:
Wide ResNet-50 (wideresnet50) is the recommended baseline backbone, achieving 99.2% AUROC on MVTec AD.

ResNetV2 (BiT)

Big Transfer (BiT) models pretrained on ImageNet-21k or ImageNet with better training. Feature Layers: Named stages vary by model - inspect with model.named_modules()

VGG Networks

Classic VGG architectures - deeper but less efficient than ResNets. Feature Layers: features[X] where X is the layer index

DenseNet

Densely connected networks with efficient parameter usage. Feature Layers: features.denseblock1, features.denseblock2, features.denseblock3, features.denseblock4 Example for Ensemble:

EfficientNet

Scaled efficient architectures with compound scaling. Feature Layers: blocks[X] where X is the block index (0-6)
EfficientNet models are optimized for different input resolutions. Ensure your image preprocessing matches the expected input size.

Vision Transformers (ViT)

Transformer-based architectures for vision tasks.

Standard ViT

DeiT (Data-efficient ViT)

Swin Transformer

Feature Layers: Varies by architecture - typically blocks[X] or hierarchical stages

MNASNet

Mobile Neural Architecture Search optimized networks. Feature Layers: layers[X]

Inception

Feature Layers: Named mixed layers like features.mixed_6a, features.mixed_7a

Legacy Networks

Feature Layer Selection

Extract features from specific layers using -le or --layer flags.

Single Backbone

Extracts and aggregates features from both layer2 and layer3.

Multiple Backbones (Ensemble)

Prefix layer names with backbone index (0-based):
  • 0.* refers to first backbone (wideresnet101)
  • 1.* refers to second backbone (resnext101)
  • 2.* refers to third backbone (densenet201)

Best Single Backbone

Performance: 99.2% Image AUROC, 98.1% Pixel AUROC

Best Ensemble

Performance: 99.6% Image AUROC, 98.2% Pixel AUROC

Memory-Efficient

Lower memory footprint with competitive performance.

High-Resolution Images

With dataset flags: --resize 366 --imagesize 320

Implementation Details

Backbone Loading

Backbones are loaded from the backbones.py module:

Sources

  • torchvision.models: Standard PyTorch models (ResNet, VGG, WideResNet, etc.)
  • timm: PyTorch Image Models library (ViT, EfficientNet, DeiT, Swin, etc.)
  • pretrainedmodels: Legacy models (BN-Inception)

Inspecting Feature Layers

To find available layers for a backbone:
Common patterns:
  • ResNet family: layer1, layer2, layer3, layer4
  • DenseNet: features.denseblock1 through features.denseblock4
  • EfficientNet: blocks[0] through blocks[6]
  • ViT: blocks[0] through blocks[11] (base)

Performance Considerations

GPU Memory Usage

Approximate memory requirements (224x224 images, batch size 1):
  • ResNet-50: ~4GB
  • Wide ResNet-50: ~6GB
  • Wide ResNet-101: ~8GB
  • Ensemble (3 networks): ~10-11GB
  • ViT-Large: ~8GB
  • EfficientNet-B7: ~12GB

Inference Speed

Relative speeds on RTX 3090 (images/sec):
  • ResNet-50: ~100
  • Wide ResNet-50: ~80
  • DenseNet-201: ~60
  • EfficientNet-B5: ~50
  • ViT-Base: ~70
  • Ensemble (3 networks): ~30

Accuracy vs. Efficiency

Recommended backbones by use case:
  • Highest accuracy: Ensemble of WideResNet101 + ResNeXt101 + DenseNet201
  • Best balance: WideResNet-50 (single backbone)
  • Fastest: ResNet-50
  • Most memory-efficient: MNASNet-100 or EfficientNet-B1
For production deployments, WideResNet-50 offers the best trade-off between accuracy (99.2% AUROC) and computational efficiency.