DetectionChinese & English

Anomaly / Defect Detection (Anomalib)

Anomaly / Defect Detection (Anomalib) is a Dragonfly plugin for unsupervised anomaly / defect detection. The key idea: you only need a batch of defect-free ("normal") images to train a model — no defect annotations requi

Updated 2026-07-09User manual

异常 / 缺陷检测 (Anomalib) 插件用户手册

Anomaly / Defect Detection (Anomalib) - User Manual

Dragonfly Prototype Apps · Anomaly / Defect Detection (Anomalib)...

版本 Version 1.0 · 2026-07-09


第一部分 中文手册

目录

1. 简介

2. 适用场景

3. 安装与启用

4. 运行环境与首次配置

5. 界面说明

6. 使用步骤

7. 参数说明

8. 输出结果

9. 常见问题与故障排除

10. 注意事项与已知限制

11. 参考资料

1. 简介

异常 / 缺陷检测 (Anomalib) 是一个 Dragonfly 插件,用于无监督的异常 / 缺陷检测。它的核心思想是:你只需要一批“无缺陷”的正常图像来训练模型,完全不需要对缺陷进行任何标注。训练完成后,把模型应用到待测的 Channel 上,插件会逐切片计算一张异常热力图(分数越高越异常),并以新的热力图 Channel 形式发布回场景;随后按阈值将异常区域二值化,发布为一个缺陷 MultiROI,可直接用于测量与可视化。

底层引擎为开源库 Anomalib(基于 PyTorch / PyTorch-Lightning)。插件内置三种可选的异常检测模型:PatchCore、PaDiM 和 FastFlow。其中 PatchCore 与 PaDiM 属于“记忆库 / 特征分布”类模型,训练时一次前向遍历即可拟合;FastFlow 属于基于梯度下降、按 Epoch(轮次)训练的归一化流模型。

本插件主要面向 2D 图像;对于 3D Channel,插件会逐切片(slice/slab-wise)处理:每个 z 切片视为一张独立图像,分别计算异常图后再堆叠回原网格。所有繁重计算(PyTorch CUDA + Anomalib)都在插件独立的虚拟环境(venv)子进程中运行,通过基于文件的 JSON 进程间通信(IPC)与面板交互,绝不进入 Dragonfly 自带的 Python,因此不会污染或拖慢 Dragonfly 本身。

许可证要点: 底层的 Anomalib、PyTorch、torchvision 等均为开源库,由 Setup Environment 在独立环境中联网安装,插件本身不打包这些库,也不打包任何预训练权重——预训练骨干网络权重在首次训练 / 应用时由 Anomalib 在该环境内自动下载。使用时请遵循各上游库及其权重的许可证条款。

2. 适用场景

本插件特别适用于“正常样本容易获得、缺陷样本稀少”的检测场景——你无法为每一种缺陷都收集足够多的标注样本,但手上有大量合格(良品)样品。只需用合格样品训练,模型即可自动定位偏离“正常”分布的区域。典型应用包括:

  • 工业与材料 CT / 显微镜图像中的裂纹、孔隙、夹杂、异物等异常检测;
  • 铸件及增材制造(3D 打印)零件的表面 / 内部缺陷检测;
  • 半导体、电子元件及表面质检中的偏差识别;
  • 任何“缺陷罕见、良品充足”的质量检测任务——用良品训练一个“正常性”模型,再用它标记出异常区域。

无监督方法会标记出所有“偏离正常”的区域,这既可能是真实缺陷,也可能是正常但少见的结构变化。建议结合阈值调节和目视复核来确认结果。

3. 安装与启用

本插件随 Prototype Apps 完整安装包(Full Package)一起分发。安装步骤如下:

1. 将安装包解压到任意较短的目录(例如 C:\PL\,避免过深路径导致的“路径过长”错误)。

2. 双击运行 `Install_FullPackage.bat`。

3. 在弹出的对话框中选择核心安装模式(Fresh 全新安装 / Compatible 兼容安装),并在应用列表中勾选本插件“Anomaly / Defect Detection (Anomalib)...”。注意:所有插件默认未勾选,需要手动勾选才会启用。

4. 点击 Install,等待控制台完成安装。

5. 完全退出并重启 Dragonfly(菜单只在启动时扫描)。

重启后,插件出现在 Dragonfly 菜单:Prototype Apps ▸ Anomaly / Defect Detection (Anomalib)...(位于 Detection 检测分组,与 LocateAnything、SCRFD 等检测类插件并列)。点击即可打开一个可停靠 / 浮动的面板。

以后修改启用状态: 最方便的方式是在 Dragonfly 内打开 Developer ▸ Prototype Labs... ▸ Menu Item Manager,在底部的 “Prototype Apps (Full Package)” 列表中勾选 / 取消本插件,重启 Dragonfly 生效。停用从不删除插件已搭建的环境,重新启用后立即可用。也可以随时重跑安装器修改勾选。

启用 / 停用菜单项只影响菜单是否出现;它不会触碰插件的运行环境(venv)和设置。因此停用再启用不需要重新执行 Setup Environment。

4. 运行环境与首次配置

本插件采用代码目录内独立虚拟环境(venv-in-code)的隔离方式:繁重的机器学习依赖不会安装进 Dragonfly。首次使用前,必须先在 Setup(设置)分页中构建这个环境。

4.1 Setup Environment 做什么

点击 Setup 分页里的 Setup Environment(build venv + install torch + anomalib) 按钮后,插件会:

1. 用一个基础 Python(默认是 Dragonfly 自带的 `Python_env\python.exe`,无需另外安装 Python)创建一个独立 venv;

2. 在 venv 内升级 pip / setuptools / wheel;

3. 从指定的 CUDA 轮子源(默认 https://download.pytorch.org/whl/cu124)安装 torch + torchvision;

4. 安装其余依赖(anomalib + numpy 等);

5. 做一次导入自检,报告 torch 版本、CUDA 是否可用及 GPU 名称,并把 venv 的 python 路径回填到面板。

该 venv 建在已安装插件代码目录下的 venv\ 子目录中(即 %LOCALAPPDATA%\comet\<Dragonfly版本>\pythonUserExtensions\GenericMenuItems\Anomalib\venv)。安装成功后,venv 的 python 路径会显示在 “Anomalib venv python” 字段中并被持久保存。

4.2 下载体积与硬件要求

首次 Setup 需要联网,会下载 torch CUDA 轮子 + anomalib,总量约数 GB,耗时可能达数分钟。运行训练 / 应用需要一块 NVIDIA GPU;仅用于推理(应用)时 CPU 也能运行,但速度很慢。

预训练权重不打包在插件里: Anomalib 所用的预训练骨干网络权重(如 PatchCore / PaDiM 的特征提取器、FastFlow 的 timm 骨干)在首次训练 / 应用时由 Anomalib 在该 venv 内按需自动下载,因此第一次训练 / 应用也需要联网。

4.3 失败时的替代方案

  • Base Python(build)字段: 留空即使用当前 Dragonfly 自带的 python(推荐)。若默认 Python 缺少 venv 模块或构建失败,可在此填入另一套 CPython 3.9+ 的路径(例如 C:\Python312\python.exe)或写 py -3.12。
  • Torch CUDA wheel index 字段: 若你的显卡驱动对应不同的 CUDA 版本,可把该地址改成匹配的源(例如把 cu124 换成 cu121)。
  • venv 重建: 如果之前的 venv 只建到一半(有 python.exe 但没有可用的 pip),再次点击 Setup Environment 会自动重建该 venv,无需手动删除。
  • Run mode(运行模式): 提供 windows(默认,已发布可用)与 wsl 两个选项;正式发布仅支持 windows 模式。

5. 界面说明

面板顶部是一段蓝色说明文字,概述“训练→应用”的整体流程。下方为三个分页 Setup / Train / Apply;面板最底部有一行绿色结果摘要和一个只读的日志窗口,实时显示进度与信息。

5.1 Setup(设置)分页

控件

类型

说明

Anomalib venv python

文本框

venv 的 python 路径;由 Setup Environment 自动填写,一般无需手动修改。

Base Python (build)

文本框

构建 venv 所用的基础 Python;留空 = 使用当前 Dragonfly 自带的 python.exe(推荐)。

Run mode

下拉框

运行模式,可选 windows(默认)/ wsl;正式仅支持 windows。

Torch CUDA wheel index

文本框

安装 torch 的 CUDA 轮子源;默认 https://download.pytorch.org/whl/cu124。

Setup Environment

按钮

构建 venv 并安装 torch + torchvision + anomalib。

5.2 Train(训练)分页

控件

类型

默认值 / 范围

说明

Output folder

文本框 + 浏览

C:\AnomalibWorkspace

工作区输出文件夹;训练 / 应用产生的中间文件与模型都保存在此。

Refresh channels

按钮

-

重新扫描当前场景中的 Channel,刷新下拉列表。

Normal-image Channel

下拉框

(场景中的 Channel)

选择用于训练的无缺陷(正常)图像 Channel。

Model

下拉框

PatchCore

异常检测模型:PatchCore / PaDiM / FastFlow。

Image size (px)

数值框

256(范围 64–1024,步长 32)

训练 / 推理时图像被缩放到的边长。

Epochs (FastFlow only; 0 = default)

数值框

0(0–500;0 显示为 default)

训练轮次;仅对 FastFlow 生效,选择其他模型时该框自动禁用。

Train

按钮

-

开始训练;完成后模型文件夹会自动填入 Apply 分页。

5.3 Apply(应用)分页

控件

类型

默认值

说明

Model folder

文本框 + 浏览

(训练后自动填入)

由 Train 产生的已训练模型文件夹。

Model (must match Train)

下拉框

PatchCore

应用时使用的模型,必须与训练时一致。

Test Channel

下拉框 + Refresh

(场景中的 Channel)

选择待检测的测试 Channel。

Threshold mode

下拉框

auto

阈值模式:auto(自动 F1 最优)/ manual(手动指定)。

Manual threshold (0-1)

数值框

0.5(0.000–1.000,步长 0.05)

手动阈值;仅当模式为 manual 时可用。

Heatmap title

文本框

(空 = Anomaly_heatmap)

生成的热力图 Channel 标题。

Defect ROI title

文本框

(空 = Anomaly_defects)

生成的缺陷 MultiROI 标题。

Apply -> heatmap Channel + defect MultiROI

按钮

-

应用模型,发布热力图 Channel 与缺陷 MultiROI。

6. 使用步骤

6.1 训练一个异常模型

输入要求: 一个只包含无缺陷(正常)图像的 Channel。2D Channel 视为一张图像;3D Channel 则把每个 z 切片当作一张正常图像。

1. 打开面板,进入 Setup 分页,首次使用先点击 Setup Environment 并等待环境构建完成(见第 4 章)。

2. 切到 Train 分页,设置 Output folder(输出工作区)。

3. 点击 Refresh channels,在 Normal-image Channel 下拉框中选择你的正常图像 Channel。

4. 在 Model 中选择模型(默认 PatchCore);如需可调整 Image size;若选择 FastFlow,可设置 Epochs。

5. 点击 Train。插件把正常 Channel 导出为 (n,y,x) 的图像堆栈,交给 venv 运行器拟合模型;日志窗口会显示进度(如 epoch、AUROC、F1)。

6. 完成后,结果摘要显示 “Trained.”,训练好的模型文件夹会自动填入 Apply 分页,模型选择也会同步。

6.2 应用模型进行缺陷检测

输入要求: 一个待检测的测试 Channel,以及一个由 Train 产生的模型文件夹。

1. 切到 Apply 分页,确认 Model folder 指向已训练模型文件夹(通常已自动填好),并确认 Model 与训练时一致。

2. 点击 Refresh,在 Test Channel 下拉框中选择待检测 Channel。

3. 选择 Threshold mode:auto 让模型自动挑选 F1 最优阈值;manual 则在 Manual threshold 中填入 0–1 之间的固定值。

4. 如需自定义输出名称,填写 Heatmap title 与 Defect ROI title(留空则用默认名)。

5. 点击 Apply。插件导出测试 Channel、在 venv 中逐切片推理、把异常图归一化到 [0,1]、按阈值二值化。

6. 完成后,插件在场景中发布一个异常热力图 Channel 和一个缺陷 MultiROI,并在结果摘要中报告使用的阈值和缺陷切片数。

7. 参数说明

参数

默认值

说明

Base Python (build)

空 = Dragonfly 自带 python

构建 venv 的基础解释器,需为 CPython 3.9+ 且带 stdlib venv + pip。

Torch CUDA wheel index

https://download.pytorch.org/whl/cu124

torch / torchvision 的 CUDA 轮子源;应与显卡驱动的 CUDA 版本匹配。

Run mode

windows

运行模式;正式仅支持 windows(wsl 为预留选项)。

Output folder

C:\AnomalibWorkspace

训练 / 应用的工作区,存放中间文件与模型文件夹。

Model

PatchCore

异常检测模型:PatchCore / PaDiM(单次拟合)、FastFlow(按 Epoch 训练)。

Image size (px)

256

训练 / 推理时图像缩放的边长;范围 64–1024,步长 32。

Epochs

0(default)

训练轮次;仅 FastFlow 生效,0 表示使用默认(FastFlow 默认约 50 轮),其他模型固定为单次拟合。

Threshold mode

auto

auto = 使用模型拟合出的 F1 最优阈值;manual = 使用下方手动值。

Manual threshold (0-1)

0.5

手动阈值,归一化异常分数空间 [0,1];分数 ≥ 阈值判为缺陷。仅 manual 模式可用。

Heatmap title

Anomaly_heatmap

输出热力图 Channel 的标题(留空取默认)。

Defect ROI title

Anomaly_defects

输出缺陷 MultiROI 的标题(留空取默认)。

阈值作用在归一化到 [0,1] 的异常分数上(0 = 最正常,1 = 最异常),因此手动阈值也应填在 0–1 之间;超出范围会被自动截断到 [0,1]。

8. 输出结果

应用(Apply) 成功后,插件在 Dragonfly 场景中(基于源 Channel 的网格 / 间距 / 原点)生成两类对象:

  • 异常热力图 Channel(默认标题 Anomaly_heatmap):逐切片的异常分数图,已归一化到 [0,1],分数越高越异常。可在 2D / 3D 视图中叠加显示,或套用彩色 LUT 直观查看异常分布。
  • 缺陷 MultiROI(默认标题 Anomaly_defects):对热力图按阈值二值化得到的缺陷掩膜,标出被判定为异常的区域,可直接用于测量(面积 / 体积 / 计数)与可视化。

结果摘要行会给出使用的阈值以及“缺陷切片数 / 总切片数”。所有中间文件(导出的图像堆栈、热力图与掩膜 .npy、日志)保存在 Output folder 下按时间戳命名的 apply_* / train_* 子文件夹,以及 model_* 模型文件夹中。

训练(Train) 的产物是一个 model_<模型名> 文件夹,内含拟合好的检查点与一个记录模型名的 anomalib_model.json;该文件夹即 Apply 分页所需的“Model folder”。

9. 常见问题与故障排除

问:点击 Train / Apply 时提示 “venv not set. Run Setup Environment first.”

答:说明还没有构建独立环境。请先到 Setup 分页点击 Setup Environment 并等待完成,venv python 路径会自动填好,之后再训练 / 应用。

问:Setup Environment 失败,提示 venv 创建失败或没有 venv 模块。

答:说明所选基础 Python 缺少 stdlib venv 或 pip。请在 Base Python (build) 字段填入另一套 CPython 3.9+(例如 C:\Python312\python.exe)后重试;若 venv 只建到一半,再次点击按钮会自动重建。

问:torch 安装失败,或提示 CUDA 不可用。

答:请确认本机有 NVIDIA GPU 且驱动正常,并把 Torch CUDA wheel index 改成与你驱动匹配的 CUDA 版本(如 cu121 / cu124)。仅做推理时 CPU 也能跑,但会很慢。首次训练 / 应用还需联网下载预训练权重。

问:Train / Apply 时下拉框里看不到我的 Channel。

答:点击 Refresh channels / Refresh 重新扫描当前场景;确认该 Channel 已加载到场景中。训练必须选“正常(无缺陷)”图像 Channel;应用选待检测的测试 Channel。

问:检测结果误报太多 / 太少,怎么调?

答:把 Threshold mode 切到 manual,手动调节 Manual threshold:调高阈值会减少误报(标记更少区域),调低阈值会更敏感(标记更多区域)。也可尝试更换模型或增大 Image size。

问:Apply 提示 “apply finished but no anomaly heatmap was produced”。

答:说明运行器未产出热力图。请检查 Model folder 是否为有效的已训练模型文件夹、Model 是否与训练时一致,并查看日志窗口的详细报错(如缺失输入、CUDA 显存不足等)。

10. 注意事项与已知限制

  • 无监督方法的本质: 模型只学习“什么是正常”,凡偏离正常分布者都会被标记——真实缺陷与罕见但正常的变化都可能被标出,请结合阈值与目视复核确认。
  • 主要面向 2D: 3D Channel 按切片逐层独立处理再堆叠,不建模切片间的三维上下文。
  • 模型必须匹配: Apply 时选择的 Model 必须与训练该模型时一致,否则检查点无法正确加载。
  • Epochs 仅对 FastFlow 生效: PatchCore / PaDiM 为单次拟合,设置轮次无效(该框会自动禁用)。
  • 硬件与显存: 训练 / 推理需要 NVIDIA GPU;PatchCore 的记忆库可能较大,大图或大数据集请注意显存占用;应用阶段逐切片推理以控制内存。
  • 首次联网: 首次 Setup 及首次训练 / 应用都需要联网(下载依赖与预训练权重)。
  • Anomalib 版本敏感: Anomalib 的 API 在不同版本间有差异,requirements 未固定确切版本;若上游版本变化导致行为异常,请重新执行 Setup Environment。

11. 参考资料

  • Anomalib(异常检测库):https://github.com/openvinotoolkit/anomalib
  • PyTorch:https://pytorch.org
  • PyTorch CUDA 轮子源:https://download.pytorch.org/whl/cu124
  • PatchCore 论文:Roth et al., “Towards Total Recall in Industrial Anomaly Detection” (2022)
  • PaDiM 论文:Defard et al., “PaDiM: a Patch Distribution Modeling Framework for Anomaly Detection and Localization” (2020)
  • FastFlow 论文:Yu et al., “FastFlow: Unsupervised Anomaly Detection and Localization via 2D Normalizing Flows” (2021)

本手册中的界面控件、参数默认值与工作流程均依据插件当前版本的实际代码整理。


Part II English Manual

Contents

1. Overview

2. Use Cases

3. Installation & Enabling

4. Runtime Environment & First-Run Setup

5. Interface Guide

6. Step-by-Step Usage

7. Parameter Reference

8. Outputs

9. FAQ & Troubleshooting

10. Notes & Known Limitations

11. References

1. Overview

Anomaly / Defect Detection (Anomalib) is a Dragonfly plugin for unsupervised anomaly / defect detection. The key idea: you only need a batch of defect-free ("normal") images to train a model — no defect annotations required. Once trained, you apply the model to a test Channel: the plugin computes a per-slice anomaly heatmap (higher = more anomalous) and publishes it back as a new heatmap Channel, then thresholds it into a defect MultiROI ready for measurement and visualization.

The underlying engine is the open-source Anomalib library (built on PyTorch / PyTorch-Lightning). Three anomaly-detection models are offered: PatchCore, PaDiM, and FastFlow. PatchCore and PaDiM are memory-bank / feature-distribution models that fit in a single forward pass; FastFlow is a normalizing-flow model trained by gradient descent over Epochs.

The plugin is primarily for 2D images; a 3D Channel is processed slice/slab-wise: each z-slice is treated as an independent image, its anomaly map computed, then stacked back onto the source grid. All heavy computation (PyTorch CUDA + Anomalib) runs in the plugin's own isolated virtual environment (venv) subprocess, talking to the panel via file-based JSON IPC, and never in Dragonfly's bundled Python — so it neither pollutes nor slows down Dragonfly itself.

Licensing note: Anomalib, PyTorch, torchvision and the rest are open-source libraries installed into the isolated environment by Setup Environment over the internet. The plugin bundles none of them and bundles no pretrained weights — pretrained backbone weights are downloaded automatically by Anomalib inside that environment at first train/apply. Please observe the licenses of each upstream library and its weights.

2. Use Cases

This plugin is especially useful when normal samples are plentiful but defect examples are rare — you cannot collect enough labeled examples of every defect, but you have many good (in-spec) parts. Train on the good parts, and the model automatically locates regions that deviate from "normal". Typical applications:

  • Industrial and materials CT / microscopy images: cracks, pores, inclusions, or foreign objects;
  • Castings and additive-manufactured (3D-printed) parts: surface or internal defects;
  • Semiconductor, electronics, and surface-quality inspection: deviation detection;
  • Any quality-inspection task where defects are rare but good parts abound — train a "normality" model on the good parts, then flag anomalous regions.

An unsupervised method flags everything that deviates from normal — this can be a real defect or merely a rare-but-valid structural variation. Combine threshold tuning with visual review to confirm results.

3. Installation & Enabling

This plugin ships as part of the Prototype Apps Full Package. To install:

1. Unzip the package into any short folder (e.g. C:\PL\) to avoid "path too long" errors.

2. Double-click `Install_FullPackage.bat`.

3. In the dialog, choose a core install mode (Fresh or Compatible) and tick "Anomaly / Defect Detection (Anomalib)..." in the app list. Note: all plugins are OFF by default — you must tick it to enable it.

4. Click Install and wait for the console to finish.

5. Quit and restart Dragonfly completely (menus are only scanned at startup).

After the restart, the plugin appears at Prototype Apps ▸ Anomaly / Defect Detection (Anomalib)... (in the Detection group, alongside detection plugins like LocateAnything and SCRFD). Clicking it opens a dockable / floating panel.

Changing the enable state later: the easiest way is inside Dragonfly — open Developer ▸ Prototype Labs... ▸ Menu Item Manager and tick / untick this plugin in the "Prototype Apps (Full Package)" list, then restart Dragonfly. Disabling never deletes the plugin's built environment, so re-enabling is instant. You can also re-run the installer anytime to change your choices.

Enabling / disabling a menu entry only affects whether the menu appears; it does not touch the plugin's environment (venv) or settings. Disabling then re-enabling does not require re-running Setup Environment.

4. Runtime Environment & First-Run Setup

The plugin uses a venv-in-code isolation model: the heavy ML dependencies are never installed into Dragonfly. Before first use you must build this environment on the Setup tab.

4.1 What Setup Environment does

Clicking Setup Environment (build venv + install torch + anomalib) on the Setup tab will:

1. Create an isolated venv using a base Python (by default Dragonfly's own `Python_env\python.exe`, so no separate Python install is needed);

2. Upgrade pip / setuptools / wheel inside the venv;

3. Install torch + torchvision from the CUDA wheel index (default https://download.pytorch.org/whl/cu124);

4. Install the rest of the stack (anomalib + numpy, etc.);

5. Run an import smoke test reporting the torch version, whether CUDA is available, and the GPU name, then fill the venv python path back into the panel.

The venv is created in a venv\ sub-folder inside the installed plugin code directory (%LOCALAPPDATA%\comet\<Dragonfly version>\pythonUserExtensions\GenericMenuItems\Anomalib\venv). On success, the venv python path shows in the "Anomalib venv python" field and is persisted.

4.2 Download size & hardware requirements

The first Setup needs internet and downloads torch CUDA wheels + anomalib, totaling several GB and taking a few minutes. Training / applying needs an NVIDIA GPU; a CPU can run inference (apply) only, but slowly.

Pretrained weights are not bundled: the pretrained backbone weights Anomalib uses (e.g. the PatchCore / PaDiM feature extractor, FastFlow's timm backbone) are downloaded lazily inside that venv at first train/apply — so the first train/apply also needs internet.

4.3 Fallbacks when setup fails

  • Base Python (build) field: leave blank to use the current Dragonfly's own python (recommended). If that Python lacks venv or the build fails, enter another CPython 3.9+ path (e.g. C:\Python312\python.exe) or write py -3.12.
  • Torch CUDA wheel index field: if your driver targets a different CUDA version, change the URL to match (e.g. replace cu124 with cu121).
  • venv rebuild: if a previous venv was only half-built (has python.exe but no working pip), clicking Setup Environment again rebuilds it automatically — no manual cleanup needed.
  • Run mode: offers windows (default, shipped) and wsl; only windows is supported in the shipped build.

5. Interface Guide

The top of the panel shows a blue note summarizing the train-then-apply flow. Below it are three tabs Setup / Train / Apply; at the very bottom sit a green result summary line and a read-only log view that streams progress and messages.

5.1 Setup tab

Control

Type

Description

Anomalib venv python

Text field

The venv's python path; filled automatically by Setup Environment — usually no need to edit.

Base Python (build)

Text field

Base Python used to build the venv; blank = use the current Dragonfly's own python.exe (recommended).

Run mode

Dropdown

Run mode; windows (default) / wsl. Only windows is supported.

Torch CUDA wheel index

Text field

The CUDA wheel index for torch; default https://download.pytorch.org/whl/cu124.

Setup Environment

Button

Builds the venv and installs torch + torchvision + anomalib.

5.2 Train tab

Control

Type

Default / Range

Description

Output folder

Text + Browse

C:\AnomalibWorkspace

Workspace output folder; intermediates and the model folder are saved here.

Refresh channels

Button

-

Rescan the current scene's Channels and refresh the dropdowns.

Normal-image Channel

Dropdown

(Channels in scene)

Select the defect-free (normal) image Channel to train on.

Model

Dropdown

PatchCore

Anomaly model: PatchCore / PaDiM / FastFlow.

Image size (px)

Spin box

256 (range 64-1024, step 32)

The side length images are resized to for training / inference.

Epochs (FastFlow only; 0 = default)

Spin box

0 (0-500; 0 shows as default)

Training epochs; only effective for FastFlow — disabled for other models.

Train

Button

-

Start training; on completion the model folder is pre-filled on the Apply tab.

5.3 Apply tab

Control

Type

Default

Description

Model folder

Text + Browse

(auto-filled after Train)

The trained model folder produced by Train.

Model (must match Train)

Dropdown

PatchCore

Model used for apply; must match the one used for training.

Test Channel

Dropdown + Refresh

(Channels in scene)

Select the test Channel to inspect.

Threshold mode

Dropdown

auto

Threshold mode: auto (F1-optimal) / manual (fixed value).

Manual threshold (0-1)

Spin box

0.5 (0.000-1.000, step 0.05)

Manual threshold; enabled only in manual mode.

Heatmap title

Text field

(blank = Anomaly_heatmap)

Title of the output heatmap Channel.

Defect ROI title

Text field

(blank = Anomaly_defects)

Title of the output defect MultiROI.

Apply -> heatmap Channel + defect MultiROI

Button

-

Apply the model and publish the heatmap Channel and defect MultiROI.

6. Step-by-Step Usage

6.1 Train an anomaly model

Input required: a Channel containing only defect-free (normal) images. A 2D Channel is one image; a 3D Channel treats each z-slice as one normal image.

1. Open the panel, go to the Setup tab, and on first use click Setup Environment and wait for the environment to build (see Chapter 4).

2. Switch to the Train tab and set the Output folder (workspace).

3. Click Refresh channels and pick your normal-image Channel in Normal-image Channel.

4. Choose a Model (default PatchCore); adjust Image size if needed; if you chose FastFlow, set Epochs.

5. Click Train. The plugin exports the normal Channel to an (n,y,x) image stack and hands it to the venv runner to fit the model; the log shows progress (epoch, AUROC, F1).

6. On completion the result line reads "Trained." and the trained model folder is pre-filled on the Apply tab, with the model selector kept in sync.

6.2 Apply the model to detect defects

Input required: a test Channel to inspect, and a model folder produced by Train.

1. Switch to the Apply tab, confirm Model folder points to the trained model folder (usually already filled), and that Model matches the training model.

2. Click Refresh and pick the Channel to inspect in Test Channel.

3. Choose a Threshold mode: auto lets the model pick the F1-optimal threshold; manual lets you enter a fixed 0-1 value in Manual threshold.

4. Optionally set Heatmap title and Defect ROI title (blank uses the default names).

5. Click Apply. The plugin exports the test Channel, runs inference slice by slice in the venv, normalizes the anomaly map to [0,1], and thresholds it into a binary mask.

6. On completion the plugin publishes an anomaly heatmap Channel and a defect MultiROI into the scene, and the result line reports the threshold used and the number of defect slices.

7. Parameter Reference

Parameter

Default

Description

Base Python (build)

blank = Dragonfly's own python

Base interpreter that builds the venv; must be CPython 3.9+ with stdlib venv + pip.

Torch CUDA wheel index

https://download.pytorch.org/whl/cu124

The CUDA wheel index for torch / torchvision; should match your driver's CUDA version.

Run mode

windows

Run mode; only windows is supported (wsl is a reserved option).

Output folder

C:\AnomalibWorkspace

Workspace for training / applying; holds intermediates and the model folder.

Model

PatchCore

Anomaly model: PatchCore / PaDiM (single-pass fit) or FastFlow (epoch-based).

Image size (px)

256

The side length images are resized to for training / inference; range 64-1024, step 32.

Epochs

0 (default)

Training epochs; only FastFlow uses it, 0 means default (FastFlow's default is ~50); other models always fit in one pass.

Threshold mode

auto

auto = use the model's fitted F1-optimal threshold; manual = use the value below.

Manual threshold (0-1)

0.5

Manual threshold in the normalized anomaly-score space [0,1]; score >= threshold is a defect. Enabled only in manual mode.

Heatmap title

Anomaly_heatmap

Title of the output heatmap Channel (default if left blank).

Defect ROI title

Anomaly_defects

Title of the output defect MultiROI (default if left blank).

The threshold acts on the anomaly score normalized to [0,1] (0 = most normal, 1 = most anomalous), so a manual threshold should also be in 0-1; values outside that range are clamped to [0,1].

8. Outputs

After a successful Apply, the plugin creates two kinds of objects in the Dragonfly scene (on the source Channel's grid / spacing / origin):

  • Anomaly heatmap Channel (default title Anomaly_heatmap): a per-slice anomaly-score map normalized to [0,1] — higher = more anomalous. It can be overlaid in 2D / 3D views or displayed with a color LUT to visualize the anomaly distribution.
  • Defect MultiROI (default title Anomaly_defects): the binary defect mask from thresholding the heatmap, marking regions judged anomalous. Ready for measurement (area / volume / count) and visualization.

The result summary line reports the threshold used and "defect slices / total slices". All intermediate files (the exported image stack, heatmap and mask .npy files, logs) are saved under timestamped apply_* / train_* sub-folders in the Output folder, along with the model_* model folder.

The Train output is a model_<name> folder containing the fitted checkpoint plus an anomalib_model.json recording the model name; that folder is the "Model folder" the Apply tab needs.

9. FAQ & Troubleshooting

Q: Clicking Train / Apply says "venv not set. Run Setup Environment first."

A: The isolated environment hasn't been built. Go to the Setup tab, click Setup Environment, and wait for it to finish — the venv python path fills in automatically — then train / apply.

Q: Setup Environment fails, saying venv creation failed or there is no venv module.

A: The chosen base Python lacks stdlib venv or pip. Enter another CPython 3.9+ in Base Python (build) (e.g. C:\Python312\python.exe) and retry; if a venv was half-built, clicking the button again rebuilds it automatically.

Q: torch install fails, or it reports CUDA is not available.

A: Confirm the machine has an NVIDIA GPU with a working driver, and set Torch CUDA wheel index to match your driver's CUDA version (e.g. cu121 / cu124). A CPU can run inference only (slowly). The first train / apply also needs internet to download pretrained weights.

Q: I don't see my Channel in the Train / Apply dropdown.

A: Click Refresh channels / Refresh to rescan the current scene, and confirm the Channel is loaded. Train needs a normal (defect-free) image Channel; Apply needs the test Channel to inspect.

Q: Too many false positives / too few detections — how do I tune it?

A: Switch Threshold mode to manual and adjust Manual threshold: raising it reduces false positives (marks fewer regions), lowering it is more sensitive (marks more). You can also try a different model or a larger Image size.

Q: Apply reports "apply finished but no anomaly heatmap was produced".

A: The runner produced no heatmap. Check that Model folder is a valid trained-model folder, that Model matches the training model, and read the log for the detailed error (e.g. missing input, CUDA out of memory).

10. Notes & Known Limitations

  • Nature of unsupervised detection: the model only learns "what is normal"; anything deviating from the normal distribution is flagged — real defects and rare-but-valid variations alike. Combine thresholds with visual review.
  • Primarily 2D: a 3D Channel is processed slice by slice and stacked back, without modeling 3D context across slices.
  • Model must match: the Model selected for Apply must match the one used to train, otherwise the checkpoint cannot load correctly.
  • Epochs affect FastFlow only: PatchCore / PaDiM fit in a single pass; setting epochs has no effect (the field is auto-disabled).
  • Hardware & VRAM: training / inference needs an NVIDIA GPU; PatchCore memory banks can be large, so watch VRAM for big images or datasets; Apply infers one slice at a time to bound memory.
  • First-run internet: the first Setup and the first train / apply both require internet (to download dependencies and pretrained weights).
  • Anomalib is version-sensitive: Anomalib's API varies across versions and requirements do not pin an exact version; if upstream changes cause issues, re-run Setup Environment.

11. References

  • Anomalib (anomaly detection library): https://github.com/openvinotoolkit/anomalib
  • PyTorch: https://pytorch.org
  • PyTorch CUDA wheel index: https://download.pytorch.org/whl/cu124
  • PatchCore: Roth et al., "Towards Total Recall in Industrial Anomaly Detection" (2022)
  • PaDiM: Defard et al., "PaDiM: a Patch Distribution Modeling Framework for Anomaly Detection and Localization" (2020)
  • FastFlow: Yu et al., "FastFlow: Unsupervised Anomaly Detection and Localization via 2D Normalizing Flows" (2021)

The UI controls, parameter defaults, and workflow described in this manual reflect the plugin's current implementation.

You’ve reached the end of this manual.Explore the library →