()
| 109 | |
| 110 | |
| 111 | def main(): |
| 112 | args = parse_args() |
| 113 | |
| 114 | assert args.out or args.eval or args.format_only or args.show \ |
| 115 | or args.show_dir, \ |
| 116 | ('Please specify at least one operation (save/eval/format/show the ' |
| 117 | 'results / save the results) with the argument "--out", "--eval"' |
| 118 | ', "--format-only", "--show" or "--show-dir"') |
| 119 | |
| 120 | if args.eval and args.format_only: |
| 121 | raise ValueError('--eval and --format_only cannot be both specified') |
| 122 | |
| 123 | if args.out is not None and not args.out.endswith(('.pkl', '.pickle')): |
| 124 | raise ValueError('The output file must be a pkl file.') |
| 125 | |
| 126 | cfg = Config.fromfile(args.config) |
| 127 | if args.cfg_options is not None: |
| 128 | cfg.merge_from_dict(args.cfg_options) |
| 129 | # import modules from string list. |
| 130 | if cfg.get('custom_imports', None): |
| 131 | from mmcv.utils import import_modules_from_strings |
| 132 | import_modules_from_strings(**cfg['custom_imports']) |
| 133 | # set cudnn_benchmark |
| 134 | if cfg.get('cudnn_benchmark', False): |
| 135 | torch.backends.cudnn.benchmark = True |
| 136 | |
| 137 | cfg.model.pretrained = None |
| 138 | if cfg.model.get('neck'): |
| 139 | if isinstance(cfg.model.neck, list): |
| 140 | for neck_cfg in cfg.model.neck: |
| 141 | if neck_cfg.get('rfp_backbone'): |
| 142 | if neck_cfg.rfp_backbone.get('pretrained'): |
| 143 | neck_cfg.rfp_backbone.pretrained = None |
| 144 | elif cfg.model.neck.get('rfp_backbone'): |
| 145 | if cfg.model.neck.rfp_backbone.get('pretrained'): |
| 146 | cfg.model.neck.rfp_backbone.pretrained = None |
| 147 | |
| 148 | # in case the test dataset is concatenated |
| 149 | samples_per_gpu = 1 |
| 150 | if isinstance(cfg.data.test, dict): |
| 151 | cfg.data.test.test_mode = True |
| 152 | samples_per_gpu = cfg.data.test.pop('samples_per_gpu', 1) |
| 153 | if samples_per_gpu > 1: |
| 154 | # Replace 'ImageToTensor' to 'DefaultFormatBundle' |
| 155 | cfg.data.test.pipeline = replace_ImageToTensor( |
| 156 | cfg.data.test.pipeline) |
| 157 | elif isinstance(cfg.data.test, list): |
| 158 | for ds_cfg in cfg.data.test: |
| 159 | ds_cfg.test_mode = True |
| 160 | samples_per_gpu = max( |
| 161 | [ds_cfg.pop('samples_per_gpu', 1) for ds_cfg in cfg.data.test]) |
| 162 | if samples_per_gpu > 1: |
| 163 | for ds_cfg in cfg.data.test: |
| 164 | ds_cfg.pipeline = replace_ImageToTensor(ds_cfg.pipeline) |
| 165 | |
| 166 | # init distributed env first, since logger depends on the dist info. |
| 167 | if args.launcher == 'none': |
| 168 | distributed = False |
no test coverage detected