Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问这个报错:AttributeError: 'EfficientFormerClsHead' object has no attribute 'post_process',没有post_process()方法? #93

Open
couleur123123 opened this issue Mar 26, 2024 · 6 comments

Comments

@couleur123123
Copy link

No description provided.

@Fafa-DL
Copy link
Owner

Fafa-DL commented Apr 1, 2024

报错信息帖完整~

@couleur123123
Copy link
Author

Loading D:\PyProj\pretrain\efficientformer-l3_3rdparty_in1k_20220803-dde1c8c5.pth
The model and loaded state dict do not match exactly

size mismatch for head.head.weight: copying a param with shape torch.Size([1000, 512]) from checkpoint, the shape in current model is torch.Size([4, 512]).
size mismatch for head.head.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([4]).
size mismatch for head.dist_head.weight: copying a param with shape torch.Size([1000, 512]) from checkpoint, the shape in current model is torch.Size([4, 512]).
size mismatch for head.dist_head.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([4]).
unexpected key in source state_dict: backbone.network.1.0.proj.weight, backbone.network.1.0.proj.bias, backbone.network.1.0.norm.weight, backbone.network.1.0.norm.bias, backbone.network.1.0.norm.running_mean, backbone.network.1.0.norm.running_var, backbone.network.1.0.norm.num_batches_tracked, backbone.network.2.0.proj.weight, backbone.network.2.0.proj.bias, backbone.network.2.0.norm.weight, backbone.network.2.0.norm.bias, backbone.network.2.0.norm.running_mean, backbone.network.2.0.norm.running_var, backbone.network.2.0.norm.num_batches_tracked, backbone.network.3.0.proj.weight, backbone.network.3.0.proj.bias, backbone.network.3.0.norm.weight, backbone.network.3.0.norm.bias, backbone.network.3.0.norm.running_mean, backbone.network.3.0.norm.running_var, backbone.network.3.0.norm.num_batches_tracked

missing keys in source state_dict: backbone.network.1.0.conv.weight, backbone.network.1.0.conv.bias, backbone.network.1.0.bn.weight, backbone.network.1.0.bn.bias, backbone.network.1.0.bn.running_mean, backbone.network.1.0.bn.running_var, backbone.network.2.0.conv.weight, backbone.network.2.0.conv.bias, backbone.network.2.0.bn.weight, backbone.network.2.0.bn.bias, backbone.network.2.0.bn.running_mean, backbone.network.2.0.bn.running_var, backbone.network.3.0.conv.weight, backbone.network.3.0.conv.bias, backbone.network.3.0.bn.weight, backbone.network.3.0.bn.bias, backbone.network.3.0.bn.running_mean, backbone.network.3.0.bn.running_var

Train: Epoch 1/100: 0%| | 0/651 [00:14<?, ?it/s<class 'dict'>]
Traceback (most recent call last):
File "D:\PyProj\Learn\Awesome-Backbones-main\utils\train_utils.py", line 221, in train
preds, losses = model(images, targets=targets, return_loss=True, train_statu=True)
File "E:\SoftwareInstall\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\SoftwareInstall\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "E:\SoftwareInstall\Anaconda\envs\pytorch\lib\site-packages\torch\nn\parallel\data_parallel.py", line 183, in forward
return self.module(*inputs[0], **module_kwargs[0])
File "E:\SoftwareInstall\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\SoftwareInstall\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "D:\PyProj\Learn\Awesome-Backbones-main\models\build.py", line 132, in forward
return self.forward_test(x), self.forward_train(x, **kwargs)
File "D:\PyProj\Learn\Awesome-Backbones-main\models\build.py", line 143, in forward_test
out = self.head.simple_test(x, **kwargs)
File "D:\PyProj\Learn\Awesome-Backbones-main\configs\heads\efficientformer_head.py", line 81, in simple_test
return self.post_process(pred)
File "E:\SoftwareInstall\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1688, in getattr
raise AttributeError(f"'{type(self).name}' object has no attribute '{name}'")
AttributeError: 'EfficientFormerClsHead' object has no attribute 'post_process'

@couleur123123
Copy link
Author

请问为什么一开始模型就匹配不上?

@Fafa-DL
Copy link
Owner

Fafa-DL commented Apr 3, 2024

请问为什么一开始模型就匹配不上?

因为你的分类是4类而预训练模型是1000类,分类头肯定是不匹配的,可以理解为此处加载预训练模型更多的用他的backbone而重训分类头

@couleur123123
Copy link
Author

刚开始接触不太明白,请问一下我尝试其他模型的时候用LinearClsHead这个分类头,我numclass也是直接改成4的,为什么这个分类头是可以直接匹配的?

@Fafa-DL
Copy link
Owner

Fafa-DL commented Apr 7, 2024

刚开始接触不太明白,请问一下我尝试其他模型的时候用LinearClsHead这个分类头,我numclass也是直接改成4的,为什么这个分类头是可以直接匹配的?

你改了结构当然权重匹配不上啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants