Skip to content

Adding mobilenetv3 or googlenet will cause the following bugs, can you give some suggestions #49

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

Closed
chuanfuye opened this issue Aug 7, 2020 · 4 comments
Labels
question Further information is requested

Comments

@chuanfuye
Copy link

Traceback (most recent call last):
File "/home/xiaofei/my_project/SiamTrackers/compute_params/flops-counter.pytorch/sample.py", line 35, in
net = pt_modelsargs.model
File "/home/xiaofei/anaconda3/envs/siamtracker/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
TypeError: forward() missing 1 required positional argument: 'x'

thank you

@sovrasov
Copy link
Owner

sovrasov commented Aug 7, 2020

Hi! The provided information is not enough to reproduce the bug. Please give a minimal complete example that reproduces the issue. May be #14 will help you.

@sovrasov sovrasov added the incomplete Not enough information provided to reproduce this issue label Aug 7, 2020
@chuanfuye
Copy link
Author

import sys
import argparse

import torchvision.models as models
import torch

from ptflops import get_model_complexity_info

pt_models = {'resnet18': models.resnet18,
             'resnet50': models.resnet50,
             'resnet151':models.resnet152,
             'alexnet': models.alexnet,
             'vgg16': models.vgg16,
             'squeezenet': models.squeezenet1_0,
             'densenet': models.densenet161,
             'inception': models.inception_v3,
             'shufflenetv2':models.shufflenet_v2_x1_0(),
             'googlenet':models.googlenet(),
             'mobilenet':models.mobilenet_v2()}

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='ptflops sample script')
    parser.add_argument('--device', type=int, default=0,
                        help='Device to store the model.')
    parser.add_argument('--model', choices=list(pt_models.keys()),
                        type=str, default='googlenet')
    parser.add_argument('--result', type=str, default=None)
    args = parser.parse_args()

    if args.result is None:
        ost = sys.stdout
    else:
        ost = open(args.result, 'w')

    net = pt_models[args.model]()

    if torch.cuda.is_available():
        net.cuda(device=args.device)

    macs, params = get_model_complexity_info(net, (3, 224, 224),
                                             as_strings=True,
                                             print_per_layer_stat=True,
                                             ost=ost)
    print('{:<30}  {:<8}'.format('Computational complexity: ', macs))
    print('{:<30}  {:<8}'.format('Number of parameters: ', params))

Thank you for your replyWhen I run resnet or alexnet, this is OK, but running mobilenet or Googlenet will display the above bug

@sovrasov
Copy link
Owner

sovrasov commented Aug 7, 2020

Dict with models is supposed to contain types, not objects.
Try 'googlenet':models.googlenet(), -> 'googlenet':models.googlenet, and so on.

@sovrasov sovrasov added question Further information is requested and removed incomplete Not enough information provided to reproduce this issue labels Aug 7, 2020
@chuanfuye
Copy link
Author

thank you very much,It worked well

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

No branches or pull requests

2 participants