DonaldRR / SimpleNet

MIT License
402 stars 59 forks source link

模型在mvtec标准数据集上训练,可以问一下为什么效果不好吗?有什么解决方案吗? #32

Closed joinusers closed 8 months ago

joinusers commented 10 months ago

(SimpleNet) bash run.sh #开始train INFO:main:Command line arguments: main.py --gpu 0 --seed 0 --log_group simplenet_mvtec --log_project MVTecAD_Results --results_path results --run_name firstone net -b wideresnet50 -le layer2 -le layer3 --pretrain_embed_dimension 1536 --target_embed_dimension 1536 --patchsize 3 --meta_epochs 40 --embedding_size 256 --gan_epochs 50 --noise_std 0.015 --dsc_hidden 1024 --dsc_layers 2 --dsc_margin .5 --pre_proj 1 dataset --batch_size 2 --resize 329 --imagesize 288 -d toothbrush mvtec DataHere #命令行参数 INFO:main:Dataset: train=60 test=42 #训练集(60good)、测试集(12good,30fefective) INFO:main:Evaluating dataset [mvtec_toothbrush] (1/1)... #训练单类别数据集“牙刷” /home/jovyan/anaconda3/envs/SimpleNet/lib/python3.8/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead. warnings.warn(/home/jovyan/anaconda3/envs/SimpleNet/lib/python3.8/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing weights=Wide_ResNet50_2_Weights.IMAGENET1K_V1. You can also use weights=Wide_ResNet50_2_Weights.DEFAULT to get the most up-to-date weights. warnings.warn(msg) INFO:main:Training models (1/1) #单类别训练结果 INFO:main:instance_auroc(I_auroc): 0.986 #表征图片good/defective分类效果
INFO:main:full_pixel_auroc(P_auroc): 0.985 #表征图片分割效果(像素级)

INFO:utils:instance_auroc(I_auroc): 0.986 #多类别平均训练效果 INFO:utils:full_pixel_auroc(P_auroc): 0.985

使用相同的命令行参数,选择test模式: INFO:main:instance_auroc(I_auroc): 0.508 INFO:main:full_pixel_auroc(P_auroc): 0.383

image
Onlydrink commented 10 months ago

你好 方便问一下你这个可视化是怎么展示出来的

joinusers commented 10 months ago

使用了utils文件定义的可视化函数

chenxixxa commented 10 months ago

我也遇到了一样的问题,训练的精度很高有99%,测试的就很低 INFO:utils:instance_auroc: 0.414 INFO:utils:full_pixel_auroc: 0.272 INFO:utils:anomaly_pixel_auroc: 0.229 楼主可以一块讨论下哇 image

joinusers commented 10 months ago

我也遇到了同样的问题,训练的精度有99%,测试的就很低 INFO:utils:instance_auroc: 0.414 INFO:utils:full_pixel_auroc: 0.272 INFO:utils:anomaly_pixel_auroc: 0.229 楼主可以讨论下哇 图像

好哇,怎么联系你呢

chenxixxa commented 10 months ago

我也遇到了同样的问题,训练的精度有99%,测试的就很低 INFO:utils:instance_auroc: 0.414 INFO:utils:full_pixel_auroc: 0.272 INFO:utils:anomaly_pixel_auroc: 0.229 楼主可以讨论下哇 图像

好哇,怎么联系你呢

chenxixxa2023@163.com

456sjd commented 10 months ago

请问下有没有直接训好的模型 我想直接测试下我的数据集

Onlydrink commented 10 months ago

请问下有没有直接训好的模型 我想直接测试下我的数据集

他给的参数已经训练好较好的效果,你可以直接用你的数据集试一下。 image 这个是他训练的结果

nanbowan6662 commented 10 months ago

你好,我也遇到了这个问题, 请问你解决了吗

rikichou commented 10 months ago

我也复现不了,有已经复现了的朋友吗?

Row Names,instance_auroc,full_pixel_auroc mvtec_screw,0.5925394548063128,0.5941589700607617 mvtec_pill,0.4162575013638843,0.6108649797694258 mvtec_capsule,0.3382528919026725,0.5600852752470121 mvtec_carpet,0.5325040128410915,0.6535846697401231 mvtec_grid,0.5964912280701754,0.43871774004861214 mvtec_tile,0.6792929292929294,0.3910630009927796 mvtec_wood,0.8342105263157895,0.6367744026677434 mvtec_zipper,0.8353466386554622,0.5154027106212969 mvtec_cable,0.41547976011994003,0.5281190755351722 mvtec_toothbrush,0.5083333333333333,0.3827801596608477 mvtec_transistor,0.5295833333333334,0.4716959814170349 mvtec_metal_nut,0.5796676441837731,0.6306286149491259 mvtec_bottle,0.673015873015873,0.5059354621788167 mvtec_hazelnut,0.7253571428571429,0.6382359505905498 mvtec_leather,0.36888586956521746,0.2398478236301243 Mean,0.5750145426437954,0.5198596544739619

joinusers commented 10 months ago

我也复现不了,有已经复现了的朋友吗?

Row Names,instance_auroc,full_pixel_auroc mvtec_screw,0.5925394548063128,0.5941589700607617 mvtec_pill,0.4162575013638843,0.6108649797694258 mvtec_capsule,0.3382528919026725,0.5600852752470121 mvtec_carpet,0.5325040128410915,0.6535846697401231 mvtec_grid,0.5964912280701754,0.43871774004861214 mvtec_tile,0.6792929292929294,0.3910630009927796 mvtec_wood,0.8342105263157895,0.6367744026677434 mvtec_zipper,0.8353466386554622,0.5154027106212969 mvtec_cable,0.41547976011994003,0.5281190755351722 mvtec_toothbrush,0.5083333333333333,0.3827801596608477 mvtec_transistor,0.5295833333333334,0.4716959814170349 mvtec_metal_nut,0.5796676441837731,0.6306286149491259 mvtec_bottle,0.673015873015873,0.5059354621788167 mvtec_hazelnut,0.7253571428571429,0.6382359505905498 mvtec_leather,0.36888586956521746,0.2398478236301243 Mean,0.5750145426437954,0.5198596544739619

可以问一下你训练了多少轮次吗

FFFox-abc commented 10 months ago

训练的精度很好99%,测试精度太低了是怎么回事呀

JoyWang1123 commented 10 months ago

请问您解决了吗 是因为什么呢 为什么训练之后没有权重文件呢(刚入门不是很懂)

jssyzsfzy commented 9 months ago

我这边也是 到底啥问题呢

Leon-Lee-WC commented 9 months ago

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

PHaiJun commented 9 months ago

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

确实如此,train()保存模型和test()加载模型不一致,改一下test()就可以了

 if "pretrained_enc" in state_dicts:
     self.feature_enc.load_state_dict(state_dicts["pretrained_enc"])
 if "pretrained_dec" in state_dicts:
     self.feature_dec.load_state_dict(state_dicts["pretrained_dec"])

改为:

if "discriminator" in state_dicts:
    self.discriminator.load_state_dict(state_dicts["discriminator"])
if "pre_projection" in state_dicts:
    self.pre_projection.load_state_dict(state_dicts["pre_projection"])

模型文件名也要保持一致

jssyzsfzy commented 8 months ago

效果就是不行 换方法了 EfficientAD可以试试 效果不错

在 2023-12-18 16:59:18,"joinusers" @.***> 写道:

Closed #32 as completed.

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

wu33learn commented 8 months ago

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

确实如此,train()保存模型和test()加载模型不一致,改一下test()就可以了

 if "pretrained_enc" in state_dicts:
     self.feature_enc.load_state_dict(state_dicts["pretrained_enc"])
 if "pretrained_dec" in state_dicts:
     self.feature_dec.load_state_dict(state_dicts["pretrained_dec"])

改为:

if "discriminator" in state_dicts:
  self.discriminator.load_state_dict(state_dicts["discriminator"])
if "pre_projection" in state_dicts:
  self.pre_projection.load_state_dict(state_dicts["pre_projection"])

模型文件名也要保持一致

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

确实如此,train()保存模型和test()加载模型不一致,改一下test()就可以了

 if "pretrained_enc" in state_dicts:
     self.feature_enc.load_state_dict(state_dicts["pretrained_enc"])
 if "pretrained_dec" in state_dicts:
     self.feature_dec.load_state_dict(state_dicts["pretrained_dec"])

改为:

if "discriminator" in state_dicts:
  self.discriminator.load_state_dict(state_dicts["discriminator"])
if "pre_projection" in state_dicts:
  self.pre_projection.load_state_dict(state_dicts["pre_projection"])

模型文件名也要保持一致

我改了,但是test模式下前后结果一样啊,都非常低

wu33learn commented 8 months ago

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

请问你如何修改的,效果很好吗

Leon-Lee-WC commented 8 months ago

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

请问你如何修改的,效果很好吗

和论文里面差不多

1s3ss commented 7 months ago

@wu33learn 请问你的加载路径是怎么改的?

1s3ss commented 7 months ago

@wu33learn ok,找到了 ,谢谢

sdracula commented 7 months ago

@wu33learn ok,找到了 ,谢谢

请问你现在test效果好吗

Cutemoon1 commented 7 months ago

@sdracula 还是不行 INFO:utils:instance_auroc : 0.508 INFO:utils:full_pixel_auroc : 0.383

sdracula commented 7 months ago

@sdracula 还是不行 INFO:utils:instance_auroc : 0.508 INFO:utils:full_pixel_auroc : 0.383

test or train?

sdracula commented 7 months ago

@sdracula 还是不行 INFO:utils:instance_auroc : 0.508 INFO:utils:full_pixel_auroc : 0 我现在能复现出来了,之前有点问题也是只有0.5

Cutemoon1 commented 7 months ago

@sdracula 还是不行 INFO:utils:instance_auroc : 0.508 INFO:utils:full_pixel_auroc : 0 我现在能复现出来了,之前有点问题也是只有0.5

是test,请问你是怎么做出来的?

sdracula commented 7 months ago

@sdracula 还是不行 INFO:utils:instance_auroc : 0.508 INFO:utils:full_pixel_auroc : 0 我现在能复现出来了,之前有点问题也是只有0.5

是test,请问你是怎么做出来的?

可能是测试集的问题,重新解压一下数据集,再试一下

kimsax commented 5 months ago

因为test里面导入模型的时候有问题,那两个键名和模型名字都有问题

请问你如何修改的,效果很好吗

和论文里面差不多

您好 可以分享一下您的代码,和模型文件吗,我这边一直复现不出来好的效果,谢谢

kimsax commented 5 months ago

请问下有没有直接训好的模型 我想直接测试下我的数据集

他给的参数已经训练好较好的效果,你可以直接用你的数据集试一下。 image 这个是他训练的结果 这个库里没有参数文件和模型文件吧,请问你在哪找到的,可以分享一下吗