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

I download a model and try to use torch.load(path),but an error occurs, No such file or directory… how to solve the problem?
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\\Desktop\ Gemma文献\feature__inversion\moco\moco\moco_v1_200ep_pretrain.pth’
[Finished in 7.0s with exit code 1]
[shell_cmd: python -u "C:\Users*
\Desktop\pytorchlearning\ModelParamLearning.py"]
[dir: C:\Users*
**\Desktop\pytorchlearning]
[path: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\MATLAB\R2017b\runtime\win64;C:\Program Files\MATLAB\R2017b\bin;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\SlikSvn\bin;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0;C:\Program Files (x86)\NVIDIA C

Based on the error message your specified path is wrong and the file cannot be found at this location, so you would need to fix the path.

The file location format is not correct. In windows you can’t do it like it.
1st solution will be, save the model relative to the code directory. then don’t need to give full path like c:.

2nd
Try path like this C:/Users/myName/My Documents. “/” instead of “”.

3rd
Compose a path like raw string
model_loc = r"C:\Users\myName\My Documents"

I feel first method is easier and simple.

If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the python file path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains directories that are automatically used for searching executables when you enter a command.

In any case, if your Python script file and your data input file are not in the same directory, you always have to specify either a relative path between them or you have to use an absolute path for one of them.

I want to load weights of trained model which is save on local machine . For this i i’m using custom function but getting the following error


Can you please tell me what is this error?

fname seems to be an empty string which is why the torch.load operation fails. Make sure to pass a valid file name and rerun your script.

Hi,
Thanks for replying
The first figure is the model from which I want to load the weights .
2nd is the trained model and 3rd is the error line.
How can I load the features from a pretrained model using a custom function? Can you please help me ?

Somewhere in your script you would most likely need to create a variable with the path to the model state_dict, which currently seems to be empty. Check your code where the model is loaded and make sure you are properly defining the path to the needed files.

It’s generally better to post code snippet, which would be easier to debug, as I cannot help using your screenshots.

Here is the link to the github repository which I’m following.
https://github.com/thilinicooray/context-aware-reasoning-for-sr

I’m trying to run the main_top_down_query_context.py