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

Number of parameters? #59

Closed
underfitting opened this issue Apr 16, 2018 · 2 comments
Closed

Number of parameters? #59

underfitting opened this issue Apr 16, 2018 · 2 comments

Comments

@underfitting
Copy link

underfitting commented Apr 16, 2018

Has anyone compared number of parameters?
I tried some good accuracy models, but they are very slow.

In terms of both accuracy and speed, which model is the best one to choose?

@psavine42
Copy link

Made the following function awhile ago, and the resulting dictionary sitting around. Has number of parameters, and last layer names which I was using to pull apart the torchvision models to get feature outputs, as well as the input size to last layer (most is not verified), but the number of parameters should be straightforward.

def get_n_params(model):
    pp=0
    for p in list(model.parameters()):
        nn = 1
        for s in list(p.size()):
            nn = nn*s
        pp += nn
    return pp

def get_stats():
    res = collections.defaultdict(dict)
    for x in pretrainedmodels.model_names:
        try:
            m = pm.__dict__[x](num_classes=1000, pretrained='imagenet')
            num_params = get_n_params(m)
            name_last, layer = list(m._modules.items())[-1]
            res[x]['n_params'] = num_params
            res[x]['feature_l_name'] = name_last
            res[x]['model_out_size'] = layer.in_features
        except:
            print('err', x)
    return res

_models = {
    'squeezenet1_0': { 'n_params': 1248424, 'feature_l_name': 'last_conv'},
    'squeezenet1_1': {'n_params': 1235496, 'feature_l_name': 'last_conv'},

    'vgg11_bn': { 'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},
    'vgg13_bn': { 'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},
    'vgg16_bn': { 'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},
    'vgg19_bn': { 'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},

    'vgg11': { 'n_params': 132863336, 'feature_l_name': 'last_linear', 'model_out_size': 4096},
    'vgg13': {'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},
    'vgg16': { 'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},
    'vgg19': { 'n_params': 123642856, 'feature_l_name': 'last_linear', 'model_out_size': 4096},

    'densenet121': { 'n_params': 7978856, 'feature_l_name': 'last_linear', 'model_out_size': 1024},
    'densenet161': {'n_params': 28681000, 'feature_l_name': 'last_linear', 'model_out_size': 2208},
    'densenet169':{ 'n_params': 14149480, 'feature_l_name': 'last_linear', 'model_out_size': 1664},
    'densenet201': { 'n_params': 20013928, 'feature_l_name': 'last_linear', 'model_out_size': 1920},


    'inceptionresnetv2': { 'n_params': 55843464, 'feature_l_name': 'last_linear', 'model_out_size': 1536},
    'inceptionv3': { 'n_params': 27161264, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'inceptionv4': { 'n_params': 42679816, 'feature_l_name': 'last_linear', 'model_out_size': 1536},
    'bninception': {'n_params': 11295240, 'feature_l_name': 'last_linear', 'model_out_size': 1024},
    'xception': { 'n_params': 22855952, 'feature_l_name': 'last_linear', 'model_out_size': 2048},

    'dpn68': { 'n_params': 12611602, 'feature_l_name': 'classifier'},
    'dpn98': { 'n_params': 61570728, 'feature_l_name': 'classifier'},
    'dpn131': {'n_params': 79254504, 'feature_l_name': 'classifier'},

    'alexnet': { 'n_params': 61100840, 'feature_l_name': 'last_linear', 'model_out_size': 4096},

    'resnet18': { 'n_params': 11689512, 'feature_l_name': 'last_linear', 'model_out_size': 512},
    'resnet34': {'n_params': 21797672, 'feature_l_name': 'last_linear', 'model_out_size': 512},
    'resnet50': {'n_params': 25557032, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'resnet101': { 'n_params': 44549160, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'resnet152': { 'n_params': 60192808, 'feature_l_name': 'last_linear', 'model_out_size': 2048},

    'resnext101_32x4d': { 'n_params': 44177704, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'resnext101_64x4d': { 'n_params': 83455272, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'senet154': { 'n_params': 115088984, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'fbresnet152': {'n_params': 60268520, 'feature_l_name': 'last_linear', 'model_out_size': 2048},

    'se_resnet50': { 'n_params': 28088024, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'se_resnet101': { 'n_params': 49326872, 'feature_l_name': 'last_linear', 'model_out_size': 2048},

    'se_resnet152': { 'n_params': 66821848, 'feature_l_name': 'last_linear', 'model_out_size': 2048},
    'se_resnext50_32x4d': { 'n_params': 27559896, 'feature_l_name': 'last_linear',  'model_out_size': 2048},
    'se_resnext101_32x4d': {'n_params': 48955416, 'feature_l_name': 'last_linear', 'model_out_size': 2048},

    'nasnetalarge': {'n_params': 88753150, 'feature_l_name': 'last_linear', 'model_out_size': 4032},
    'nasnetamobile': {'n_params': 5289978, 'feature_l_name': 'last_linear', 'model_out_size': 1056},
}

@underfitting
Copy link
Author

underfitting commented Apr 28, 2018

Thank you @psavine42 ! It's so useful.
I simply calculated score = (acc@1)/(log10(n_params)) and top5 score models are below:

model name | n_params | acc@1
-------------------------------
nasnetamobile | 5289978 | 74.1
densenet121 | 7978856 | 74.6
xception | 22855952 | 78.9
dpn68 | 12611602 | 75.9
se_resnext50_32x4d | 27559896 | 79.1

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

2 participants