FileNotFoundError: [Errno 2] No such file or directory

when i try to call to save my model in a name, it rises a FileNotFoundError. the trace back is as follow:

Traceback (most recent call last):

  File "D:\python\RDANET\models\", line 236, in <module>

  File "D:\python\RDANET\models\", line 173, in save, name)

  File "d:\anaconda3\lib\site-packages\torch\", line 369, in save
    with _open_file_like(f, 'wb') as opened_file:

  File "d:\anaconda3\lib\site-packages\torch\", line 234, in _open_file_like
    return _open_file(name_or_buffer, mode)

  File "d:\anaconda3\lib\site-packages\torch\", line 215, in __init__
    super(_open_file, self).__init__(open(name, mode))

FileNotFoundError: [Errno 2] No such file or directory: 'D:/python/RDANET/checkpoints/RDAnet_0718_16_30_44.pkl'

I’m running code on a Windows remote desktop,the code:

    def save(self, name=None):

        if name is None:
            prefix = 'D:/python/RDANET/checkpoints/' + self.model_name + '_'
            name = time.strftime(prefix + '%m%d_%H_%M_%S.pkl'), name)
        return name
1 Like

I solved the problem,This works when I use prefix = self.model_name + ‘_’ .So I created the folder checkpoints. And then it didn’t go wrong. This is so strange


One or more of your intermediate directories do not exist in your path (D:/python/RDANET/checkpoints/) where you are trying to save the model. Torch expects the directories to exist in the path of saving the model.

You must create the directory manually.