Reputation: 121
I've been trying to save the state_dict of a Pytorch model with
torch.save(agent.qnetwork_local.state_dict(), filename)
where
filename = datetime.now().strftime('%d-%m-%y-%H:%M_dqnweights.pth')
type(filename)
returns str
which shouldn't be a problem with torch.save()
and it should output a non-empty file. Instead I get an empty file with just the date and time and nothing after that. Putting the date and in the middle of the filename results in an empty file with everything after the date and time cut off.
torch.save(agent.qnetwork_local.state_dict(), 'checkpoint1.pth')
and any time I hardcode the string works and gives me the expected non-empty file.
What is going on and how do I fix this?
I am running this code in a Python v3.6.8 virtualenv with Pytorch v1.8.1+cpu on Windows 10.
Upvotes: 0
Views: 1451
Reputation: 121
The colon was the problem in filename = datetime.now().strftime('%d-%m-%y-%H:%m_dqnweights.pth')
since it was running on windows.
Changing it to filename = datetime.now().strftime('%d-%m-%y-%H_%M_dqnweights.pth')
works as expected.
Upvotes: 0