yaoyao-liu / meta-transfer-learning

TensorFlow and PyTorch implementation of "Meta-Transfer Learning for Few-Shot Learning" (CVPR2019)
https://lyy.mpi-inf.mpg.de/mtl/
MIT License
731 stars 147 forks source link

how to fix feature encoder weights during SS process #52

Open mengruwg opened 3 years ago

mengruwg commented 3 years ago

during pythorch version new_weight = self.weight.mul(new_mtl_weight)(line 95 in conv2d_mtl.py) self.weight = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size))(line 42 in conv2d_mtl.py) How to load pretrained and fix feature encoder weights during SS process?

yaoyao-liu commented 3 years ago

How to freeze the convolution weights?

If you set mtl=True in the following line: https://github.com/yaoyao-liu/meta-transfer-learning/blob/fe189c96797446b54a0ae1c908f8d92a6d3cb831/pytorch/models/resnet_mtl.py#L165

It means that you're using _ConvNdMtl function, so https://github.com/yaoyao-liu/meta-transfer-learning/blob/fe189c96797446b54a0ae1c908f8d92a6d3cb831/pytorch/models/conv2d_mtl.py#L45 i.e., the convolution weights are frozen.

How to load the pre-trained model?

You may directly load normal checkpoints to MTL models like this: https://github.com/yaoyao-liu/meta-transfer-learning/blob/fe189c96797446b54a0ae1c908f8d92a6d3cb831/pytorch/trainer/meta.py#L69

If you have any further questions, feel free to ask.

mengruwg commented 3 years ago

Thanks for your detailed reply. I can completely understand the experiment now.

在 2021-05-12 17:26:14,"Yaoyao Liu" @.***> 写道:

Reopened #52.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.