throws error [Error 2 ] File or Directory not foud

when I call to save my model , it throws a FileNotFoundError. the trace back is as follow:

Following is my code.

        def save_checkpoint(self, ckpt_dir, epoch):
        #self.hparams['dataset_name'] = Iris
        #f'{}_{self.file_name} = iris_model_mlp
        path = os.path.join(
            ckpt_dir, self.hparams['dataset_name'], f'{}_{self.file_name}')

        if not os.path.exists(ckpt_dir):
                    'epoch': epoch,
                    'loss': self.loss_dict,
                    'optimizer': self.optimizer.state_dict(),
                    'scheduler': self.scheduler.state_dict()}, path , _use_new_zipfile_serialization= False)

        print(f'=> saved the model {self.file_name} to {path}')
        return path

Any Insights are helpful!!!
Torch version - 1.7.1

I guess the operation is failing, if the intermediate directory wasn’t created.
Based on your code snippet, you are creating ckpt_dir, but never check for self.hparams['dataset_name'].

@ptrblck I got the issue. The inner directory was not created so I checked for whether the directory exists or not and if not creating the directory. But now it’s throwing me access denied error as following.

It seems Windows is disallowing the Python process to create a new directory, so you could either make sure to have the right permissions or create the folder in another directory, which gives you write permissions.