Closed MaxTeselkin closed 1 year ago
Update: I was able to load model weights by modifying original state dict.
When I tried to load weights as for regular pytorch model, I received the error because every key in original state dict has preffix "model.". So I decided to remove this preffix from all state dict keys using this function:
def preprocess_state_dict(self, state_dict):
preprocessed_state_dict = {}
for key, value in state_dict.items():
preprocessed_state_dict[key[6:]] = value
return preprocessed_state_dict
After running this code the weights were loaded successfully:
checkpoint = torch.load(checkpoint_path, map_location=self.device)
raw_state_dict = checkpoint["state_dict"]
preprocessed_state_dict = self.preprocess_state_dict(raw_state_dict)
self.model.load_state_dict(preprocessed_state_dict)
Hi! I am coding a script for MBPTrack inference on custom tracklet, but I am unable to load model state dict from your .ckpt files.
Here is my code for loading model on device:
When I used this code, the weights were initialised randomly, so self.cfg.resume_from = checkpoint_path has no effect. So I decided to load model state dict as for regular pytorch model:
but got multiple size mismatch errors.
After that I tried to load state dict as for Pytorch Lightning model using:
and got size mismatch error again.
What am I doing wrong?
P.S. You have only script for testing pretrained model on specific dataset using pl.Trainer.test, which is completely not suitable for inference on custom tracklet - that's why I need to code my own script for loading model weights.