Can't Load Weights for GPU

Hi,I wanna apply weights data to model.

weight=torch.load(weights_file)
print(weight)
self.model.load_state_dict(weight)
print(self.model.state_dict())

This torch.Tensor which name is ‘weight’ has “device=‘cuda:0’”.
But “self.model.state_dict()” doesn’t have it.
Why?

It seems to me, that the weights you are trying to load, are loaded onto the GPU and your model is on the CPU, try to load the weights onto the CPU.
Here is how you load it correctly onto the CPU:

model.load_state_dict(torch.load('/path/to/weights.pt', map_location='cpu'))

It has displayed as below

load_state_dict() got an unexpected keyword argument 'map_location'

But your comment provides me with a clue.
I have solved this problem by loading the model on GPU.

self.modedl=self.model.to('cuda')

Thank you:)

map_location should be in the torch.load() method-paranthesis :wink: as in my example above, but glad I could help you anyways.