Hi everyone, I copied the weights of my trained model using “model.state_dict()” and then I want to update these weights using model.load_state_dict(weights) but I’m getting an error "AttributeError: ‘float’ object has no attribute ‘copy’ " as shown in the images below. Any ideas as to how can I can fix this?
Could you post the model definition of x_global_model
, as it seems the state_dict()
operation returns a float
, while an OrderedDict
would be expected?
It seems you are manually appending some “weights” to g_global_weights
and try to treat it as a state_dict
, which is causing the issue.
You would have to use the workflow posted previously, i.e. create the state_dict
via:
sd = model.state_dict()
and load it via:
model.load_state_dict(sd)
afterwards.
Currently you are replacing the initial state_dict
with an empty list
and append the (unknown) values.
PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier.