Skip to main content
This guide covers everything you need to install and configure PatchCore for industrial anomaly detection.

System Requirements

Python Version

Python 3.8 or higherResults were computed using Python 3.8

GPU Memory

11GB VRAM minimumRequired for most experiments at standard image sizes

Operating System

Linux (recommended)Also works on macOS and Windows with WSL2

CUDA Support

CUDA 10.2 or higherOptional but strongly recommended for GPU acceleration
Larger input images will require more GPU memory. If you plan to use 320x320 images or larger, ensure you have at least 16GB of VRAM.

Installation Steps

1

Clone the Repository

First, clone the PatchCore repository:
2

Create Virtual Environment (Recommended)

Create an isolated Python environment:
3

Install Core Dependencies

Install all required packages from requirements.txt:
This installs:
  • click >= 8.0.3: Command-line interface framework
  • torch >= 1.10.0: PyTorch deep learning framework
  • torchvision >= 0.11.1: Pre-trained models and image transforms
  • pretrainedmodels >= 0.7.4: Additional backbone architectures
  • scikit-image >= 0.18.3: Image processing
  • scikit-learn >= 1.0.1: Machine learning utilities
  • scipy >= 1.7.1: Scientific computing
  • numpy: Numerical operations (installed as dependency)
  • matplotlib >= 3.5.0: Plotting and visualization
  • pillow >= 8.4.0: Image loading and processing
  • tqdm >= 4.62.3: Progress bars
  • faiss-cpu: CPU-based similarity search (default)
  • faiss-gpu: GPU-accelerated similarity search (optional)
4

Choose FAISS Backend

By default, requirements.txt installs faiss-cpu. For significantly faster training and inference, install the GPU version:
GPU vs CPU Performance:
  • faiss-gpu: 10-50x faster similarity search, requires CUDA
  • faiss-cpu: Works everywhere but significantly slower
When using CPU FAISS, remove the --faiss_on_gpu flag from training commands.
5

Set PYTHONPATH

PatchCore requires the src directory to be in your Python path:
Instead of setting PYTHONPATH globally, you can prefix each command:
6

Verify Installation

Test that all dependencies are correctly installed:
Check PyTorch CUDA availability:
Expected output:

Optional: Install from setup.py

For a more permanent installation, you can install PatchCore as a package:
This uses the setup.py file which:
  • Installs all dependencies from requirements.txt
  • Makes the patchcore package importable from anywhere
  • Allows editable development (-e flag)

Troubleshooting

Solution: Make sure PYTHONPATH is set correctly:
Or run commands from the repository root with the prefix:
Solution: Reduce memory usage by:
  1. Using smaller image sizes: --imagesize 192 instead of --imagesize 224
  2. Reducing batch size: --batch_size 1
  3. Using smaller coreset percentage: -p 0.01 instead of -p 0.1
  4. Using CPU FAISS (slower but uses less GPU memory)
Problem: faiss-gpu fails to installSolution: Try installing via conda:
Or fall back to CPU version:
Problem: PyTorch doesn’t detect your GPUSolution: Install PyTorch matching your CUDA version:
Check your CUDA version:
Solution: Don’t run pip with sudo. Use a virtual environment or:

Hardware Recommendations

Minimum

  • GPU: GTX 1080 Ti (11GB)
  • CPU: 4 cores
  • RAM: 16GB
  • Storage: 10GB

Recommended

  • GPU: RTX 3090 (24GB)
  • CPU: 8+ cores
  • RAM: 32GB
  • Storage: 50GB

Multi-Dataset

  • GPU: A100 (40GB)
  • CPU: 16+ cores
  • RAM: 64GB
  • Storage: 100GB

Verify GPU Setup

Run this diagnostic script to check your setup:

Next Steps

Quickstart Guide

Train your first model in minutes

Dataset Setup

Prepare the MVTec AD dataset

Configuration

Understand all training parameters

API Reference

Explore the PatchCore API