ML_Decoder icon indicating copy to clipboard operation
ML_Decoder copied to clipboard

when i load model, not found key variable

Open JadeKim042386 opened this issue 1 year ago • 1 comments

https://github.com/Alibaba-MIIL/ML_Decoder/blob/8a9e984f671c9c30c98d2c45dfcaf4383381c254/src_files/models/utils/factory.py#L47-L56

when load_head is True, it didn't defined key.

+ i know solution. so, i just notified this problem. plz fix it

JadeKim042386 avatar Oct 17 '24 02:10 JadeKim042386

Modify the code like this

if 'model' in state: 
    key = 'model' 
else: 
    key = 'state_dict'
if not load_head: 
     filtered_dict = {k: v for k, v in state[key].items() if 
                      (k in model.state_dict() and 'head.fc' not in k)} 
     model.load_state_dict(filtered_dict, strict=False) 
else: 
     model.load_state_dict(state[key], strict=True) 

I found the solution in another thread in the issues answered by https://github.com/yangyangtiaoguo

Esmaeel-Hilal avatar Oct 23 '24 11:10 Esmaeel-Hilal