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()

解决

你可能感兴趣的:(#,Deep,Learning,#,Code,#,计算成像,pytorch,load,error)