Exemplo n.º 1
0
def calculate_models_params_and_flops():

    backbone='darknet53'
    network = backbones.get_backbone(backbone, pretrained=False, feature_type='tri_stage_fpn', n_classes=1000)
    input = torch.randn(1, 3, 448, 448)
    bb_macs, _ = profile(network, inputs=(input, ),verbose=False)
    bb_params = summary(network,(3,448,448),device='cpu')[0].item()
    model_df = pd.DataFrame(columns=['model_name', 'params', 'mac/flops'])
    for key in model_argmap:
        model_cfg= create_model_cfg(key, model_argmap)
        model_components = create_model_components(model_cfg['name'],
                                                   preprocess_args=model_cfg['preprocess_args'],
                                                   network_args=model_cfg['network_args'],
                                                   loss_args=model_cfg['loss_args'],
                                                   postprocess_args=model_cfg['postprocess_args'],
                                                   stage='validate')
        network=model_components.network
        model_macs, model_params = profile(network, inputs=(input, ),verbose=False)
        if 'backbone' in model_cfg.network_args:
            model_macs-=bb_macs
            model_params-=bb_params
            key+='_head'
        model_macs_in_g=model_macs/(10**9)
        model_params_in_m=model_params/(10**6)
        print(key,model_params_in_m,model_macs_in_g)
        model_df = model_df.append({'model_name': key,
                                    'params': model_params_in_m,
                                    'mac/flops': model_macs_in_g}, ignore_index=True)
    model_df.to_csv('models_summary.txt',index=False)
Exemplo n.º 2
0
def calculate_backbone_params_and_flops():
    all_supported_backbones=backbones.all_models
    backbone_df = pd.DataFrame(columns=['backbone_name', 'params', 'mac/flops'])
    for backbone in all_supported_backbones:
        network = backbones.get_backbone(backbone, pretrained=False, feature_type='tri_stage_fpn', n_classes=1000)
        input = torch.randn(1, 3, 224, 224)
        macs, _ = profile(network, inputs=(input, ),verbose=False)
        params = summary(network,(3,224,224),device='cpu')[0].item()
        macs_in_g=macs/(10**9)
        params_in_m=params/(10**6)
        print(backbone,params_in_m,macs_in_g)
        backbone_df = backbone_df.append({'backbone_name': backbone,
                                          'params': params_in_m,
                                          'mac/flops': macs_in_g}, ignore_index=True)
    backbone_df.to_csv('backbones_summary.txt',index=False)