I have some models trained in PyTorch 1.5 and saved by torch.save(filename, model), instead of torch.save(filename, model.state_dict()).
Now, I am not able to load them in PyTorch 1.6.
I get torch.nn.modules.module.ModuleAttributeError: 'BatchNorm2d' object has no attribute '_non_persistent_buffers_set'
What is the correct way to load such models?
Following https://github.com/ultralytics/yolov5/issues/58 14, I tried this on the model and seemed to load without problem. But is this the right way?
model = ModelDenseNet()
model1 = torch.load(model_file)
for k, m in model1.named_modules():
   m._non_persistent_buffers_set = set()  # pytorch 1.6.0 compatability
model.load_state_dict(model1.state_dict())


Thanks