> ## Documentation Index
> Fetch the complete documentation index at: https://aegean.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# PatchCore

> Patch-based anomaly detection using pretrained CNN features and coreset sampling

## Introduction

PatchCore is a CNN-based model that uses a backbone network pretrained on large natural image datasets (ImageNet) for feature extraction.

PatchCore uses a network $\phi$ pre-trained on ImageNet. As the features at specific network hierarchies play an important role, we use $\phi_{i,j} = \phi_j(x_i)$ to denote the features for image $x_i \in X$ (with dataset $X$) and hierarchy-level $j$ of the pre-trained network $\phi$.

If not noted otherwise, $j$ indexes feature maps from ResNet-like architectures, such as ResNet-50 or WideResNet-50, with $j \in \{1, 2, 3, 4\}$ indicating the final output of respective spatial resolution blocks.

## Key Features

* **Patch-based Approach**: Operates on image patches rather than whole images
* **Coreset Sampling**: Reduces memory requirements by selecting representative patches
* **Pretrained Features**: Leverages features from networks pretrained on ImageNet

## How It Works

1. **Feature Extraction**: Extract patch-level features from intermediate layers of a pretrained CNN
2. **Memory Bank Construction**: Build a memory bank of nominal patch features
3. **Coreset Reduction**: Apply coreset sampling to reduce memory requirements while maintaining coverage
4. **Anomaly Scoring**: For test images, compute distance to nearest neighbors in the memory bank

## Cold Start Considerations

PatchCore relies heavily on a representative set of nominal features to work. During cold start scenarios, since there is limited nominal data, PatchCore's coreset reduction strategy cannot be properly applied. A simpler strategy such as random sampling can be used to build the initial nominal feature set.

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit this page on GitHub](https://github.com/aegean-ai/eaia/edit/main/src/products/applications/anomaly-detection/manufacturing/unsupervised-learning-models/patchcore/index.mdx) or [file an issue](https://github.com/aegean-ai/eaia/issues/new/choose).
</Callout>
