Parent directory \results does not exist, in pytorch when trying to save a new network

66 Views Asked by At

I am having trouble with saving my network on PyTorch.

I have the following code here: It is from this site https://nextjournal.com/gkoehler/pytorch-mnist#training-the-model

def train(epoch):
  network.train()
  for batch_idx, (data, target) in enumerate(train_loader):
    optimizer.zero_grad()
    output = network(data)
    loss = F.nll_loss(output, target)
    loss.backward()
    optimizer.step()
    if batch_idx % log_interval == 0:
      print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format(
        epoch, batch_idx * len(data), len(train_loader.dataset),
        100. * batch_idx / len(train_loader), loss.item()))
      train_losses.append(loss.item())
      train_counter.append(
        (batch_idx*64) + ((epoch-1)*len(train_loader.dataset)))
      torch.save(network.state_dict(), '/results/model.pth')
      torch.save(optimizer.state_dict(), '/results/optimizer.pth')

However I am having trouble when I run my model, it doesn't want to save. This is the error I get:

Traceback (most recent call last):

  File "<ipython-input-23-901bbf4e7eff>", line 54, in <module>
    train(epoch)

  File "<ipython-input-23-901bbf4e7eff>", line 16, in train
    torch.save(network.state_dict(), '\results\model.pth')

  File "C:\Users\User\anaconda3\lib\site-packages\torch\serialization.py", line 628, in save
    with _open_zipfile_writer(f) as opened_zipfile:

  File "C:\Users\User\anaconda3\lib\site-packages\torch\serialization.py", line 502, in 
_open_zipfile_writer
    return container(name_or_buffer)

  File "C:\Users\User\anaconda3\lib\site-packages\torch\serialization.py", line 473, in 
__init__
    super().__init__(torch._C.PyTorchFileWriter(self.name))

RuntimeError: Parent directory \results does not exist.

Where does torch.save save to on a windows PC? I don't think I have the filename that the tutorial on the website was using?

0

There are 0 best solutions below