Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.nn.modules.module.ModuleAttributeError: 'MobileNetV2' object has no attribute 'module' #25

Open
epoc88 opened this issue Dec 30, 2020 · 0 comments

Comments

@epoc88
Copy link

epoc88 commented Dec 30, 2020

This happens when try to use test.py to load the model:

pfld_backbone.load_state_dict(torch.load(args.model_path, map_location= device))

To fix this issue,
we have to change save model in the "train_model.py"


save model

checkpoint_path = os.path.join(model_dir, 'model_'+str(epoch)+'.pth')
if args.all_model:
torch.save(model, checkpoint_path)

as
torch.save(model.state_dict(), checkpoint_path)

after that all works.

I am also wondering about an alternative without changing the train_model.py. So instead of using the train_model.py, we could do the code like below:

model = torch.load(pretrained_model)
test(test_loader, model, args, device)
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant