HRNet-Semantic-Segmentation icon indicating copy to clipboard operation
HRNet-Semantic-Segmentation copied to clipboard

Loads pretrained model

Open nlvtuan opened this issue 5 years ago • 2 comments

Hi everyone,

Could you explain for me the meaning of this line https://github.com/HRNet/HRNet-Semantic-Segmentation/blob/8037a7fb867b58d885b26b1ceb8283a7ee252851/tools/test.py#L82 https://github.com/HRNet/HRNet-Semantic-Segmentation/blob/8037a7fb867b58d885b26b1ceb8283a7ee252851/tools/test.py#L83

pretrained_dict = {k[6:]: v for k, v in pretrained_dict.items() if k[6:] in model_dict.keys()}

What are k and v and why is 6 in k[6].

Thanks for your time!

nlvtuan avatar Feb 15 '21 08:02 nlvtuan

I am wondering about this too - I think it strips off the beginning of the "module." state_dict entries so that it matches the model state_dict. I think the issue is that when training with parallel GPUs each model state_dict is nested under separate "module" dict entries. It is really frustrating me because after training the model and loading it using test.py following this schema the outputs are nonsense and it seems like it is not loading the trained model at all.

I seemed to have solved the issues I'm facing by following this schema for distributed data parallel: https://pytorch.org/tutorials/intermediate/ddp_tutorial.html

This way the remapping above is not needed.

StuvX avatar Jun 26 '21 16:06 StuvX

Hi everyone,

Could you explain for me the meaning of this line https://github.com/HRNet/HRNet-Semantic-Segmentation/blob/8037a7fb867b58d885b26b1ceb8283a7ee252851/tools/test.py#L82

https://github.com/HRNet/HRNet-Semantic-Segmentation/blob/8037a7fb867b58d885b26b1ceb8283a7ee252851/tools/test.py#L83

pretrained_dict = {k[6:]: v for k, v in pretrained_dict.items() if k[6:] in model_dict.keys()}

What are k and v and why is 6 in k[6].

Thanks for your time!

key is start with “module” in muti-gpu training.

Margrate avatar Sep 02 '21 06:09 Margrate