最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Receiving "[Errno 2] No such file or directory:" when using correct path on VS Code - Stack Overflow

programmeradmin3浏览0评论

I am relatively new to VS Code (I switched from google colab). Currently, I am running code within a kernel called ipykernel, linked to an existing jupyter server (RunPod). For some reason, I keep receiving this error:

[Errno 2] No such file or directory: '/Users/brentkong/Documents/CycleGAN/Saved Items/Saved Weights/Copy of gen_h_11.pth.tar'

when I use:

torch.load(checkpoint_file, map_location = DEVICE)

to load model weights. I am using the absolute path shown below:

if LOAD_MODEL:
   #malfunction was here, gen_z and disc_z have new weights
  load_checkpoint('/Users/brentkong/Documents/CycleGAN/Saved Items/Saved Weights/Copy of gen_h_11.pth.tar', gen_H, opt_gen, LEARNING_RATE), #new (if wrong, brown spots)
  load_checkpoint('/Users/brentkong/Documents/CycleGAN/Saved Items/Saved Weights/Copy of critic_h_11.pth.tar', disc_H, opt_disc, LEARNING_RATE), #new

  load_checkpoint('/Users/brentkong/Documents/CycleGAN/Saved Items/Saved Weights/Copy of gen_z_11.pth.tar', gen_Z, opt_gen, LEARNING_RATE), #old
  load_checkpoint('/Users/brentkong/Documents/CycleGAN/Saved Items/Saved Weights/Copy of critic_z_11.pth.tar', disc_Z, opt_disc, LEARNING_RATE), #old

When I switch kernels to anaconda3, the code works perfectly and is able to find the file. However, the trouble occurs when I switch to ipykernel and link it to an existing jupyter server, where the file cannot be found. Here is what my screen looks like:

enter image description here

Thank you for your help.

Update: I worked on the problem for a bit, and I have some more information.
I followed this tutorial regarding connecting a RunPod to VSCode: .

When I run os.listdir(current_directory), I get a bunch of random files ['bin', 'boot', 'dev', 'etc'], which correspond to the files in the jupyter notebook runpod I set up (/, or something like this). So torch.load([path]) is reading files from that runpod and not from the files that I uploaded to VSCode. Is there anyway to solve this?

发布评论

评论列表(0)

  1. 暂无评论