Documentation Index
Fetch the complete documentation index at: https://mintlify.com/amazon-science/patchcore-inspection/llms.txt
Use this file to discover all available pages before exploring further.
Overview
PatchCore models can be saved after training and loaded later for evaluation or inference on new data. The saved model includes the FAISS nearest-neighbor search index and model configuration parameters.Model Structure
When a PatchCore model is saved using--save_patchcore_model, it creates the following structure:
The
.faiss file contains the memory bank of patch features from training data. The .pkl file stores backbone architecture, layer names, dimensions, and other hyperparameters.Loading a Single Model
To load a pretrained PatchCore model, use theload_from_path() method:
Configure FAISS method
Create a
FaissNN instance with GPU acceleration if available. This handles nearest-neighbor searches in the feature space.What Gets Loaded
Theload_from_path() method restores the complete model state:
Model Parameters (from patchcore_params.pkl)
Model Parameters (from patchcore_params.pkl)
Feature Memory Bank (from nnscorer_search_index.faiss)
Feature Memory Bank (from nnscorer_search_index.faiss)
The FAISS index contains:
- Coreset-subsampled patch features from training images
- Optimized data structure for fast nearest-neighbor search
- Typically 10% of original features after greedy coreset sampling
Loading Model Ensembles
PatchCore supports ensemble models for improved performance. When multiple models are saved, they use a prepend naming scheme:Memory Management
When working with multiple models or datasets, proper memory management is crucial:Implementation Details
Theload_from_path() method (source:patchcore.py:256):
- Loads pickled parameters from
patchcore_params.pkl - Reconstructs the backbone network from the saved name
- Initializes all forward modules (feature aggregator, preprocessing, etc.)
- Loads the FAISS index into the anomaly scorer
Next Steps
Run Evaluation
Evaluate loaded models on test datasets and compute metrics
Batch Prediction
Run inference on multiple images using DataLoaders
