Hi @vfdev-5 ,
Does ignite Checkpoint handler support the case that pre-trained model has different number output with the model load to?
For example, the weights in model checkpoint is for 1000 classes output, and now user defines the network with 3 classes output and use ignite handler to load pretrained model for the weights.
Thanks.
Hi @Nic-Ma
I think this is currently not supported, because we simply load the checkpoint and don't do any checks on the Tensor sizes.
We should allow kwargs in the load_objects function and you would have to pass everything except the last layer as to_load. I think implementing a general interface for that is not that easy, but I'll think on that.
Hi @Nic-Ma ,
yes, as @justusschock said this is not supported and probably the reason for that is related to the fact that pretrained weights loading in most of the cases provided by model definition (e.g. in torchvision resnet18(pretrained=True)). In that case, user's modification can be easily done a posteriori :
model = resnet18(pretrained=True)
model.fc = nn.Linear(512, 3)
@vfdev-5 we should nevertheless think about kwargs for the load_objects function, to allow kwargs for both, torch.load (for example the map_location) and the load_state_dict (for example the strict).
Yes, I agree!
Hi @vfdev-5 and @justusschock ,
Thanks very much for your sharing. Looking forward to this feature.
It's really useful for us, especially to provide "Transfer Learning" function in our product.
Currently, we can't exclude FC layer when loading weights, users raised this request.
Thanks.
Closed by #861
Most helpful comment
@vfdev-5 we should nevertheless think about kwargs for the load_objects function, to allow kwargs for both,
torch.load(for example themap_location) and theload_state_dict(for example thestrict).