---
title: PatchCore-Anomaly-Detection
canonical_url: "https://www.modelscope.cn/models/Brilliantccc/PatchCore-Anomaly-Detection"
md_url: "https://www.modelscope.cn/models/Brilliantccc/PatchCore-Anomaly-Detection.md"
repository: Brilliantccc/PatchCore-Anomaly-Detection
last_updated: 2026-09-26
license: "Apache License 2.0"
pipeline_tag: bad-image-detecting
tasks:
  - bad-image-detecting
parameters: 13.6B
tensor_type:
  - F16
library_name:
  - pytorch
  - safetensors
downloads: 80
stars: 0
---

# PatchCore-Anomaly-Detection

> PatchCore-Anomaly-Detection - Brilliantccc 在 ModelScope 开源的模型。基于 PatchCore (CVPR 2022) 的工业异常检测预训练模型，支持 MVTec AD 和 VisA 数据集。

Brilliantccc/PatchCore-Anomaly-Detection 是 ModelScope 魔搭社区上的 13.6B 参数bad-image-detecting模型，采用 Apache License 2.0 许可。

- **Repository**: Brilliantccc/PatchCore-Anomaly-Detection
- **License**: Apache License 2.0
- **Tasks**: bad-image-detecting
- **Parameters**: 13.6B
- **Downloads**: 80
- **Stars**: 0
- **Last updated**: 2026-09-26

Source: https://www.modelscope.cn/models/Brilliantccc/PatchCore-Anomaly-Detection

---

# PatchCore 异常检测模型

基于 PatchCore (CVPR 2022) 的工业异常检测预训练模型，支持 MVTec AD 和 VisA 数据集。

## 模型信息

| 项目 | 内容 |
|------|------|
| 方法 | PatchCore |
| 骨干网络 | WideResNet-50-2 |
| 特征层 | layer2 + layer3 |
| 输入尺寸 | 256 × 256 |
| 框架 | PyTorch |

## 支持的类别

### MVTec AD (15 类)

| 类别 | AUROC | F1 |
|------|-------|-----|
| bottle | 0.960 | 0.945 |
| cable | 0.991 | 0.942 |
| capsule | 0.943 | 0.836 |
| carpet | 0.992 | 0.956 |
| grid | 0.913 | 0.912 |
| hazelnut | 1.000 | 0.979 |
| leather | 1.000 | 0.984 |
| metal_nut | 0.980 | 0.938 |
| pill | 0.964 | 0.917 |
| screw | 0.819 | 0.649 |
| tile | 1.000 | 1.000 |
| toothbrush | 0.850 | 0.821 |
| transistor | 0.988 | 0.894 |
| wood | 0.984 | 0.952 |
| zipper | 0.747 | 0.742 |

**平均 AUROC: 0.942**

### VisA (12 类)

| 类别 | AUROC | F1 |
|------|-------|-----|
| candle | 0.926 | 0.678 |
| capsules | 0.590 | 0.246 |
| cashew | 0.927 | 0.825 |
| chewinggum | 0.985 | 0.946 |
| fryum | 0.905 | 0.814 |
| macaroni1 | 0.860 | 0.560 |
| macaroni2 | 0.693 | 0.229 |
| pcb1 | 0.961 | 0.810 |
| pcb2 | 0.902 | 0.732 |
| pcb3 | 0.918 | 0.750 |
| pcb4 | 0.987 | 0.911 |
| pipe_fryum | 0.974 | 0.921 |

**平均 AUROC: 0.886**

## 使用方法

### 1. 安装依赖

```bash
pip install torch torchvision safetensors numpy scikit-learn tqdm Pillow
```

### 2. 下载模型

```python
from modelscope import snapshot_download

model_dir = snapshot_download('Brilliantccc/PatchCore-Anomaly-Detection')
```

### 3. 推理示例

```python
import torch
import json
from PIL import Image
import torchvision.transforms as transforms
from models.patchcore import PatchCore

# 加载模型
model = PatchCore.load('mvtec/bottle/patchcore_model.pth', device='cuda')

# 加载阈值
with open('mvtec/bottle/config.json') as f:
    threshold = json.load(f)['threshold']

# 预处理
transform = transforms.Compose([
    transforms.Resize((256, 256)),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

image = transform(Image.open('test.jpg').convert('RGB')).unsqueeze(0).cuda()

# 推理
with torch.no_grad():
    scores, _ = model.compute_anomaly_scores(image)

print(f'异常分数: {scores.item():.4f}')
print(f'是否异常: {scores.item() > threshold}')
```

## 模型文件说明

```
mvtec/bottle/
├── config.json                # 配置（含阈值）
├── patchcore_model.pth        # 模型参数
└── memory_bank.safetensors    # 记忆库
```

## 引用

```bibtex
@inproceedings{roth2022towards,
  title={Towards total recall in industrial anomaly detection},
  author={Roth, Karsten and Pemula, Latha and Zepeda, Joaquin and Sch{\"o}lkopf, Bernhard and Brox, Thomas and Gehler, Peter},
  booktitle={CVPR},
  year={2022}
}
```
