torch.load(save_path): *** FileNotFoundError: [Errno 2] No such file or directory:

*** FileNotFoundError: [Errno 2] No such file or directory: '~/DeepLearning/.../XXXXXnet.pth'

對應的代碼爲:

weight_path = '~/DeepLearning/......'
save_path = os.path.join(weight_path, save_filename)

錯誤原因:

這裏是python不是linux,~在Python裏不能直接代表主目錄,所以要用絕對路徑。

 

更改結果:

weight_path = '/home/username/DeepLearning/......'
save_path = os.path.join(weight_path, save_filename)

 

(Pdb) network.load_state_dict(torch.load(save_path))
(Pdb) exit()

解決

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章