BangguWu / ECANet

Code for ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks
MIT License
1.24k stars 197 forks source link

Unable to load_state_dict from eca_resnet50_k3557.pth.tar #49

Open guangdafan opened 3 years ago

guangdafan commented 3 years ago

Hi,

i have tried to load_state_dict from eca_resnet50_k3557.pth.tar file and has already rename the keys, but meets a RuntimeError: Error(s) in loading state_dict for ResNet:
size mismatch for layer2.0.eca.conv.weight: copying a param with shape torch.Size([1, 1, 5]) from checkpoint, the shape in current model is torch.Size([1, 1, 3]). size mismatch for layer2.1.eca.conv.weight: copying a param with shape torch.Size([1, 1, 5]) from checkpoint, the shape in current model is torch.Size([1, 1, 3]). just like this, from layer2 to layer4

Could you please let me know how to solve this?

Thanks!

digantamisra98 commented 3 years ago

@guangdafan Simply use this in your bottleneck block to make it work:

if self.planes == 64:
        self.eca = eca_layer(k_size = 3)
elif self.planes == 128:
    self.eca = eca_layer(k_size = 5)
elif self.planes == 256:
    self.eca = eca_layer(k_size = 5)
elif self.planes == 512:
    self.eca = eca_layer(k_size = 7)
digantamisra98 commented 3 years ago

@guangdafan For context you can visit my reproduced ECANets here - https://github.com/digantamisra98/Reproducibilty-Challenge-ECANET

duduzai2019 commented 1 year ago

Hi,

i have tried to load_state_dict from eca_resnet50_k3557.pth.tar file and has already rename the keys, but meets a RuntimeError: Error(s) in loading state_dict for ResNet: size mismatch for layer2.0.eca.conv.weight: copying a param with shape torch.Size([1, 1, 5]) from checkpoint, the shape in current model is torch.Size([1, 1, 3]). size mismatch for layer2.1.eca.conv.weight: copying a param with shape torch.Size([1, 1, 5]) from checkpoint, the shape in current model is torch.Size([1, 1, 3]). just like this, from layer2 to layer4

Could you please let me know how to solve this?

Thanks!

hi, how can i use eca_resnet50_k3557.pth.tar in the windows? .tar file cannot be decompressed!

YIYIZH commented 1 year ago

hi, how can i use eca_resnet50_k3557.pth.tar in the windows? .tar file cannot be decompressed! You don't need to decompress it. Use it directly!

duduzai2019 commented 1 year ago

hi, how can i use eca_resnet50_k3557.pth.tar in the windows? .tar file cannot be decompressed! You don't need to decompress it. Use it directly!

thanks!