SeuTao / FaceBagNet

FaceBagNet - Patch-based Methods for Multi-modal Face Anti-spoofing (FAS)
664 stars 201 forks source link

Transfer learning: shape mismatch in two keys when load_pretrain() #30

Closed NachoLlorcaR closed 2 years ago

NachoLlorcaR commented 2 years ago

Hello hello!

Congrats on the outstanding project!!

I am trying to load the pretrained models provided but I run into the same shape mismatch error, always in keys encoder.last_linear.weight and encoder.last_linear.bias, no matter which .pth.tar I try to load (IR, depth or RGB; 32, 48 or 64).

The code:

bobo_A = Net()
path = "\model_A_color_64\checkpoint\global_min_acer_model.pth.tar"
bobo_A.load_pretrain(path)

Raises:

RuntimeError: Error(s) in loading state_dict for Net:
    size mismatch for encoder.last_linear.weight: copying a param with shape torch.Size([1000, 2048]) from checkpoint, the shape in current model is torch.Size([2, 2048]).
    size mismatch for encoder.last_linear.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([2]).

I am not being able to find a workaround. Any help?

Thanks!

SeuTao commented 2 years ago

I'm sorry that the codebase has been updated and I will upload new pre-trained models soon.

NachoLlorcaR commented 2 years ago

Wow that is a quick answer! I indeed saw that the repository was updated this month. I do really look forward to the new pretrained models, your paper and code is far nicer than that of the other participants in the CVPR2019 challenge. Best wishes!

SeuTao commented 2 years ago

Thank you! The patch-based methods we used are quite simple but effective(robust) in FAS tasks. I found recently proposed vision transformers or mlp models are actually patch-based architecture. It's interesting to see how they perform. So I made some minor updates and did some simple experiments using the CASIA-SURF dataset.