Skip to main content

Overview

PatchCore evaluation computes both image-level and pixel-level anomaly detection performance on test datasets. The evaluation script loads pretrained models and generates comprehensive metrics including AUROC and PRO scores.

Evaluation Script

Use bin/load_and_evaluate_patchcore.py to evaluate saved models:
1

Specify output directory

First positional argument: evaluated_results/IM224_WR50 - where results will be saved
2

Configure model loader

Use patch_core_loader with -p flags to specify model paths for each subdataset
3

Configure dataset

Use dataset command with -d flags to specify which subdatasets to evaluate

Complete Evaluation Example

Here’s a complete evaluation script for all MVTec AD categories (from sample_evaluation.sh:1):

Evaluation Metrics

The evaluation computes three key metrics for each dataset:

Image-Level AUROC

Measures the ability to classify entire images as normal or anomalous. Uses the maximum anomaly score across all patches in an image.
Area Under the Receiver Operating Characteristic Curve
  • Ranges from 0 to 1 (1.0 = perfect)
  • Measures discrimination ability across all thresholds
  • Robust to class imbalance
  • Standard metric for anomaly detection

Pixel-Level AUROC (Full)

Computed on all test images including normal images:
Measures pixel-level localization accuracy across the entire test set.

Pixel-Level AUROC (Anomaly Only)

Computed only on images containing anomalies:
Provides a more focused measure of localization performance on defective regions.

Example Output

During evaluation, you’ll see progress and results like this:
The Inferring... progress bar shows prediction progress. Evaluation metrics are computed after all predictions are complete.

Understanding the Evaluation Process

The evaluation pipeline (source:load_and_evaluate_patchcore.py:58):
1

Load models and datasets

Iterate through dataset/model pairs, loading one PatchCore model per subdataset
2

Generate predictions

Run inference on all test images to get anomaly scores and segmentation maps
3

Normalize scores

Normalize to [0, 1] range for consistent thresholding
4

Compute metrics

Calculate AUROC for image-level detection and pixel-level localization
5

Save results

Store metrics in CSV format with per-dataset breakdown

Ensemble Evaluation

For ensemble models, predictions from multiple models are aggregated:
Each ensemble member is normalized independently before averaging. This prevents models with different score ranges from dominating the ensemble.

Results Storage

Evaluation results are saved in the specified output directory:
The results.csv file contains:

Saving Segmentation Images

To visualize predictions, use the --save_segmentation_images flag:
This generates overlay images showing:
  • Original input image
  • Ground truth mask (if available)
  • Predicted anomaly heatmap
  • Anomaly score

Expected Performance

State-of-the-art pretrained models achieve:
Results may vary slightly due to hardware differences and software versions, but should be within 0.1-0.3% of reported values.

Next Steps

Load Models

Learn how to load and initialize saved models

Batch Prediction

Run inference on custom image datasets