【论文实现】Anomaly Clustering: Grouping Images into Coherent Clusters of Anomaly Types

Code Implementation

Please see Anomaly Clustering folder which is the code integration of the whole project.

Algorithm implementation using Pytorch for
Anomaly Clustering: Grouping Images into Coherent Clusters of Anomaly Types.
Improve the algorithm with
DINO
pretrained ViT. Implement algorithms based on
PatchCore.

Background

Anomaly detection is a subtask of computer vision, typically formulated as a binary classification problem. However, the
expressive power of binary classification labels is limited, and it is more practical to divide the data into multiple
semantically coherent clusters. This paper reproduces the newly proposed
Anomaly Clustering
method, and proposes to use
DINO
(self-distillation with no labels) method pre-trained ViT as a feature extractor for anomaly clustering to improve the
clustering performance. The Anomaly Clustering method utilizes pre-trained image patch embeddings and traditional
clustering methods to divide the data into coherent clusters of anomaly types. The method uses the Euclidean distance
between weighted average embeddings as the distance function between images. The weights represent the importance of
instances (i.e., image patches, which can highlight defective regions and they can be computed in an unsupervised way or
in a semi-supervised way when normal data is available. The DINO method employs label-free self-distillation,
simplifying self-supervised training and enhancing the representation power of output feature maps by directly
predicting the output of a teacher network constructed by momentum encoders using a standard cross-entropy loss. The
model performs well on ImageNet. This paper conducts experiments on the defect detection dataset
MVTec AD
to verify the effectiveness of the method. Compared to the method in the paper, using the DINO method pre-trained ViT
as the backbone for image feature extraction improves clustering performance and achieves
state-of-the-art performance.

Usage

First, put dataset in the folder data/mvtec_ad. Notice that the dataloader mvtec.py in the folder datasets is just
a copy of models/datasets/mvtec.py. When we run the program, we actually run into the original one.

###Calculate Matrix Alpha
To calculate the matrix alpha, use

PYTHONPATH=models python examples/main.py --path data/mvtec_ad --backbone_names dino_vitbase8 --layers_to_extract_from blocks.10 blocks.11 --pretrain_embed_dimension 2048 --target_embed_dimension 4096 --output_dir outputs --patchsize 3 --tau 1 --train_ratio 1 --supervised unsupervised --dataset mvtec_ad

path is the path to the dataset.

backbone_names are the backbone feature maps extractors. You can check the available backbones in
models/patchcore/backbones.py

layers_to_extract_from are the different layers used to fuse multiscale features.

pretrained_embed_dimension is the target dimension of single layer features.

target_embed_dimension is the target dimension of multi layer fused-features.

output_dir is directory to save matrix alpha and X.

patchsize is the n*n neighborhood of patch embeddings to fuse.

tau controls the smoothness of matrix alpha.

train_ratio is the ratio of training picture used in semi-supervised situation.

supervised is the situation choosed from unsupervised, supervised and average.

dataset is mvtec_ad.

Normally, we use a list of tau to calculate the matrix alpha. We change for tau in [tau]: tofor tau in tau_list:.

tau_list:is a list of tau.

###Calculate Metrics
To calculate the metrics of clustering: NMI, ARI, F1-micro. use

PYTHONPATH=models python examples/test.py

Normally, we calculate the results of different tau. However, when we are interested in the effect of other parameters,
we can change for tau in tau_list: to other statement such as for train_ratio in train_ratio_list:
or for layer in layer_list:.

###Draw Matrix Alpha

PYTHONPATH=models python utils/draw_alpha.py

You must modify the parameters in the draw_alpha.py including

dataset is the dataset name.

path_local is the local path of the dataset

supervised is choosed from unsupervised, supervised and average.

backbone_names are the backbone feature maps extractors.

layers_to_extract_from are the different layers used to fuse multiscale features.

pretrained_embed_dimension is the target dimension of single layer features.

target_embed_dimension is the target dimension of multi layer fused-features.

tau controls the smoothness of matrix alpha.

train_ratio is the ratio of training picture used in semi-supervised situation.

Result

MVTec(object)AverageUnsupervisedSupervised
MetricsNMIARIF1NMIARIF1NMIARIF1
WideResNet500.3100.1880.4340.4350.3050.5440.5610.4190.623
ViT Base0.3500.2410.4770.3180.1540.4480.4590.3050.567
DINO ViT Base0.3720.2270.4850.4300.2920.5430.6080.4960.696
MVTec(texture)AverageUnsupervisedSupervised
MetricsNMIARIF1NMIARIF1NMIARIF1
WideResNet500.4480.2900.5020.6610.5590.7100.6720.5780.740
ViT Base0.6850.6100.7360.6480.5690.7280.7270.6540.786
DINO ViT Base0.6350.5510.6960.7570.6860.8060.7900.7410.857

Related Efforts

  • PatchCore - Mainly based on PatchCore for code development.
  • DINO - Using DINO pretrained ViT to extract feature maps, and reached
    state-of-the-art result in Anomaly Clustering.

Maintainers

@KevinWangHP.

License

This project is licensed under the Apache-2.0 License.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值