[Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute

The error code is as follows:

# Error code!
model = model.load_state_dict(state_dict_var)
out = model(input)

There are some problems on the Internet because the saved model uses state_ DCIT() to load, or vice versa.

The error here is different from the above because xxx.load_state_Dict() does not require a return value to receive.

Amend to read as follows:

# Correct code!
model.load_state_dict(state_dict_var)
out = model(input)

I hope it will help more people.

Read More: