zhangzjn / ADer

ADer (https://arxiv.org/abs/2406.03262) is an open source visual anomaly detection toolbox based on PyTorch, which supports multiple popular AD datasets and approaches.
https://arxiv.org/abs/2406.03262
187 stars 13 forks source link

How to call the trained weights for testing #28

Open zhaiyuyang opened 1 month ago

zhaiyuyang commented 1 month ago

It seems that the model saves the weights in the format net_xxx.pth during training. However, during testing, I made the following modifications according to your method: `self.model_t = Namespace() self.model_t.name = 'vit_small_patch16_224_dino' self.model_t.kwargs = dict(pretrained=False, checkpoint_path= 'model/pretrain/net_100.pth', pretrained_strict=False, strict=True, img_size=self.size, teachers=[3, 6, 9], neck=[12])

self.model_t.kwargs = dict(pretrained=True, checkpoint_path='', strict=True, img_size=self.size, teachers=[3, 6, 9], neck=[12])

    self.model_f = Namespace()
    self.model_f.name = 'fusion'
    self.model_f.kwargs = dict(pretrained=False, checkpoint_path='', strict=False, dim=384, mul=1)
    self.model_s = Namespace()
    self.model_s.name = 'de_vit_small_patch16_224_dino'
    self.model_s.kwargs = dict(pretrained=False, checkpoint_path='', strict=False,
                               img_size=self.size, students=[3, 6, 9], depth=9)
    self.model = Namespace()
    self.model.name = 'vitad'
    self.model.kwargs = dict(pretrained=False, checkpoint_path='', strict=True, model_t=self.model_t,
                             model_f=self.model_f, model_s=self.model_s)`

But an error occurred during execution: RuntimeError: Error(s) in loading state_dict for ViT_Encoder:`,"Clearly, the weight file does not match the model input."。 "Could you please advise me on how to resolve this? Thank you in advance for your response."

zhaiyuyang commented 1 month ago

Can someone come to help me?

zhangzjn commented 2 weeks ago

You can modify trainer.resume_dir to LOGDIR, or model.kwargs['checkpoint_path'] to LOGDIR/net_xxx.pth. I hope this helps you.