(args, model_without_ddp: nn.Module)
| 13 | |
| 14 | |
| 15 | def get_param_dict(args, model_without_ddp: nn.Module): |
| 16 | try: |
| 17 | param_dict_type = args.param_dict_type |
| 18 | except: |
| 19 | param_dict_type = 'default' |
| 20 | assert param_dict_type in ['default', 'ddetr_in_mmdet', 'large_wd'] |
| 21 | |
| 22 | # by default |
| 23 | if param_dict_type == 'default': |
| 24 | param_dicts = [{ |
| 25 | 'params': [ |
| 26 | p for n, p in model_without_ddp.named_parameters() |
| 27 | if 'backbone' not in n and p.requires_grad |
| 28 | ] |
| 29 | }, { |
| 30 | 'params': [ |
| 31 | p for n, p in model_without_ddp.named_parameters() |
| 32 | if 'backbone' in n and p.requires_grad |
| 33 | ], |
| 34 | 'lr': |
| 35 | args.lr_backbone, |
| 36 | }] |
| 37 | return param_dicts |
| 38 | |
| 39 | if param_dict_type == 'ddetr_in_mmdet': |
| 40 | param_dicts = [{ |
| 41 | 'params': [ |
| 42 | p for n, p in model_without_ddp.named_parameters() |
| 43 | if not match_name_keywords(n, args.lr_backbone_names) |
| 44 | and not match_name_keywords(n, args.lr_linear_proj_names) |
| 45 | and p.requires_grad |
| 46 | ], |
| 47 | 'lr': |
| 48 | args.lr, |
| 49 | }, { |
| 50 | 'params': [ |
| 51 | p for n, p in model_without_ddp.named_parameters() |
| 52 | if match_name_keywords(n, args.lr_backbone_names) |
| 53 | and p.requires_grad |
| 54 | ], |
| 55 | 'lr': |
| 56 | args.lr_backbone, |
| 57 | }, { |
| 58 | 'params': [ |
| 59 | p for n, p in model_without_ddp.named_parameters() |
| 60 | if match_name_keywords(n, args.lr_linear_proj_names) |
| 61 | and p.requires_grad |
| 62 | ], |
| 63 | 'lr': |
| 64 | args.lr * args.lr_linear_proj_mult, |
| 65 | }] |
| 66 | return param_dicts |
| 67 | |
| 68 | if param_dict_type == 'large_wd': |
| 69 | param_dicts = [{ |
| 70 | 'params': [ |
| 71 | p for n, p in model_without_ddp.named_parameters() |
| 72 | if not match_name_keywords(n, ['backbone']) |
no test coverage detected