Getting error when loading adam optimizer state dict


I’m working on training a light GAN on Google Colab and thus need to resume training over a couple of sessions. I can save and load the generator and discriminator state dicts A-OK, but get the following error when trying to load the adam optimizer state dicts:

TypeError                                 Traceback (most recent call last)
<ipython-input-27-cbfbe7dc0130> in <module>()
      4 G.cuda()
      5 D.cuda()
----> 6 g_optimizer.load_state_dict(torch.load('/content/drive/MyDrive/GAN_Temp/g_optim.pth'))
      7 d_optimizer.load_state_dict(torch.load('/content/drive/MyDrive/GAN_Temp/d_optim.pth'))

/usr/local/lib/python3.7/dist-packages/torch/optim/ in load_state_dict(self, state_dict)
    135         # Validate the state_dict
    136         groups = self.param_groups
--> 137         saved_groups = state_dict['param_groups']
    139         if len(groups) != len(saved_groups):

TypeError: 'method' object is not subscriptable

I would save the the state dicts like so:, '/content/drive/MyDrive/GAN_Temp/G.pth'), '/content/drive/MyDrive/GAN_Temp/D.pth'), '/content/drive/MyDrive/GAN_Temp/g_optim.pth'), '/content/drive/MyDrive/GAN_Temp/d_optim.pth')

Originally I was trying to save them at the end of every so-and-so batch iterations in my training loop, but I’ve also tried to let a full few epochs complete and run the save steps above, then reload the state dict before a new running the training loop again – same results.

I feel like I’m probably just doing something silly, but any ideas?

You are storing the state_dict methods in:, '/content/drive/MyDrive/GAN_Temp/g_optim.pth'), '/content/drive/MyDrive/GAN_Temp/d_optim.pth')

and would need to call this method to store the actual state_dict:, '/content/drive/MyDrive/GAN_Temp/g_optim.pth'), '/content/drive/MyDrive/GAN_Temp/d_optim.pth')

I am a fool! Not sure why I was thinking those were attributes, but I’ll leave my ignorance here for others. Thanks!