Pytorch error: 'BiSeNet' object has no attribute 'module'
I'm new to pytorch and I'm trying to study BiSeNet for image segmentation (code took from a github repo: https://github.com/ooooverflow/BiSeNet/blob/master/train.py). During the training phase, after some training epochs, the net performs validation and tryes to save the parameters of the model if the results of the val are better than the previous ones.
During this last operation, I get this error in line 109 (and also 102 during training):
AttributeError: 'BiSeNet' object has no attribute 'module'
I do not paste all the code here, but just the main steps.
First of all, they built the model like that:
os.environ['CUDA_VISIBLE_DEVICES'] = args.cuda
model = BiSeNet(args.num_classes, args.context_path)
if torch.cuda.is_available() and args.use_gpu:
        model = model.cuda()

So there exists a BiSeNet object created thanks to an imported module called &quot;model&quot; where there is a file named build_BiSeNet.py; In this script the class BiSeNet is defined and there is no attribute named module.
Looking at the pytorch documentation, seems like in the Model class there is an attribute called modules which contains the module I'd like to save.
In the docs, they suggest also to do torch.save(model.state_dict(), ...) in order to save the model, without calling the module attribute Ilike it is done in the line 109)
So, finally, my question is: In order to avoid the error that gives me, should I remove .module in line 109 (and so also in line 102) or maybe change this attribute to .modules?

Look at their demo.py, they are defining the model:
model = BiSeNet(args.num_classes, args.context_path)
if torch.cuda.is_available() and args.use_gpu:
  model = torch.nn.DataParallel(model).cuda()

Once you wrap the model with nn.DataParallel you get an &quot;extra&quot; .module in your way.
The saved checkpoint does not have this extra .module and therefore, when loading a saved checkpoint:
model.module.load_state_dict(torch.load(args.checkpoint_path))

It is not loaded to the model directly, but rather to the model.module.
