ld-lsi icon indicating copy to clipboard operation
ld-lsi copied to clipboard

Confused in loading weights

Open sachinsharma9780 opened this issue 3 years ago • 1 comments

#loading weights

  1. model_w = torch.load('Desktop/ld-lsi/res/weights/weights_erfnet_road.pth')
  2. new_mw = {}
  3. for k,w in model_w.items():
  4. new_mw[k[7:]] = w
    
  5. roadnet.load_state_dict(new_mw)
roadnet.to(device)
roadnet.eval();

I am a little confused here: 1). In 1. we are loading pretrained weights of erfnet_road model, so these are the weights of the model which is mentioned in the paper (giving 76% acc on BDD100k) or these are the pretrained weights of encoder trained on ImageNet dataset? 2) so what line 3 and 4 are doing is taking each layer, omitting module word from there and taking its corresponding weights and saving them in new_mw dict and everything else remains the same then what is difference between new_mw and model_w since they both have the same weights for each layer. 3) What is the role of pretrained network (weights_erfnet_road.pth) here? What if I want to train the model from scratch i.e without using pretrained weights can I get the same results as mentioned in the paper ?

Thank You!

sachinsharma9780 avatar Sep 12 '20 17:09 sachinsharma9780

You are right in points 1 and 2 here. There is no difference except if you try to load model_w directly, it does not work for some reason. For 3, just train the network without the command roadnet.load_state_dict(new_mw)

khizar-anjum avatar Sep 21 '20 19:09 khizar-anjum