[Python] Receiving "[Errno 2] No such file or directory:" when using correct path on VS Code

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página