FuNz-0 / PromptAD

Official implementation of CVPR 2024 PromptAD: Learning Prompts with Only Normal Samples for Few-Shot Anomaly Detection
The Unlicense
85 stars 4 forks source link

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

Open yoho131 opened 2 months ago

yoho131 commented 2 months ago

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

yoho131 commented 2 months ago

额,不好意思,我在阅读代码后能跑起来了,但因为我的数据集图像尺寸是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

FuNz-0 commented 2 months ago

你需要对position embedding 做个上采样,vit 源码里应该是有这部分的实现的

------------------ 原始邮件 ------------------ 发件人: yoho131 @.> 发送时间: 2024年7月17日 19:47 收件人: lxf1293763074 @.> 主题: Re: [FuNz-0/PromptAD] 如何在自建数据集训练并测试? (Issue #13)

额,不好意思,我在阅读代码后能跑起来了,但因为我的数据集图像尺寸是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.png (view on web) 其中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.png (view on web) 所以应该在哪里修改image_size呢?我将此处修改为1024不起作用 image.png (view on web)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

yoho131 commented 2 months ago

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