AttributeError: 'Net' object has no attribute 'module'

state_dict = net.module.state_dict()

when I execute above code, I got the error: AttributeError: ‘Net’ object has no attribute ‘module’, how can I deal with it? Thanks a lot.

If you want to get the state of the whole network, you should use net.state_dict().

If you just want to get the state of a specific sub-module, you should use the sub-module name like net.sub_module_name.state_dict().


Thank you very much. I will try this right away.

In official tutorial, they suggest “, PATH) " when using Dataparallel
But when I try this, I met same problem [‘Net’ object has no attribute ‘module’].
Why? So should I always save model using "”?


Always use net=torch.nn.DataParallel(net) even if you only have one GPU. The problem will not occur.

Thank you! I will try this when saving and loading models.
But still don’t understand why the official tutorial add “module” when saving model.

It feels pretty head banging ,when model is trained for 5 minutes and get this type of error