1. 程式人生 > >pytorch 如何載入部分預訓練模型

pytorch 如何載入部分預訓練模型

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

pretrained_dict =...

model_dict = model.state_dict()


# 1. filter out unnecessary keys
pretrained_dict = {k: v for k, vin pretrained_dict.items() if k inmodel_dict}


# 2. overwrite entries in the existing state dict

model_dict.update(pretrained_dict)


# 3. load the new state dict

model.load_state_dict(model_dict)           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述