FuNz-0 / PromptAD

Official implementation of CVPR 2024 PromptAD: Learning Prompts with Only Normal Samples for Few-Shot Anomaly Detection

Repository from Github https://github.comFuNz-0/PromptADRepository from Github https://github.comFuNz-0/PromptAD

如何在自建数据集训练并测试?

yoho131 opened this issue · comments

首先感谢开源你的项目代码。
我想问问我该如何在自建数据集运行代码呢?
我在尝试后报错如下
image

额,不好意思,我在阅读代码后能跑起来了,但因为我的数据集图像尺寸是51205120,如果resize为240240效果太差。
所以我将train_seg.py和tesst_seg.py中的--img-cropsize和--img-resize设置为1024,运行后报错
RuntimeError: The size of tensor a (4097) must match the size of tensor b (226) at non-singleton dimension 1,
报错位置如下
image
其中x.shape为(1,4097,896),self.positional_embedding.shape为(226,896)
当我再次研究代码后知道了其中226(226=(240/16)^2+1)的源头是此处的image_size和patch_size,如果能将此处的image_size修改为1024,patch_size不变就能得到self.positional_embedding.shape为(4097,896)
image
所以应该在哪里修改image_size呢?我将此处修改为1024不起作用
image

commented

如果我直接在PromptAD/CLIPAD/transformer.py的此处直接将self.grid_size修改为(64,64)会对检测效果有什么影吗?我尝试修改后代码可以运行,但我不知道是否会对checkpoint的性能造成影响
image