Torch.load ordereddict

I want to my pretrained resnet32.pth to resnet32.wts for quantization

resnet50.pth provided by torchvision

net = torch.load(‘resnet50.pth’)
net =‘cuda:0’)

is working but resnet32.pth that i trained by me isn’t working

net = torch.load(‘resnet32.pth’)
net =‘cuda:0’)

AttributeError: ‘collections.OrderedDict’ object has no attribute ‘to’

resnet50.pth is resnet and resnet32.pth is ordereddict so i want to change resnet32.pth to resnet

resnet32.pth seems to be a state_dict so you would need to either create the model object beforehand using its actual source code before loading this state_dict or you could try to save the entire model (as was apparently done for resnet50), which can fail in multiple ways if you don’t guarantee to restore the source tree on the machine trying to load the model.

1 Like