HRNet / HRNet-Semantic-Segmentation

The OCR approach is rephrased as Segmentation Transformer: https://arxiv.org/abs/1909.11065. This is an official implementation of semantic segmentation for HRNet. https://arxiv.org/abs/1908.07919
Other
3.13k stars 686 forks source link

Loads pretrained model #209

Open nlvtuan opened 3 years ago

nlvtuan commented 3 years ago

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!

StuvX commented 3 years ago

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.

Margrate commented 3 years ago

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.