(args)
| 275 | |
| 276 | |
| 277 | def build(args): |
| 278 | # the `num_classes` naming here is somewhat misleading. |
| 279 | # it indeed corresponds to `max_obj_id + 1`, where max_obj_id |
| 280 | # is the maximum id for a class in your dataset. For example, |
| 281 | # COCO has a max_obj_id of 90, so we pass `num_classes` to be 91. |
| 282 | # As another example, for a dataset that has a single class with id 1, |
| 283 | # you should pass `num_classes` to be 2 (max_obj_id + 1). |
| 284 | # For more details on this, check the following discussion |
| 285 | # https://github.com/facebookresearch/detr/issues/108#issuecomment-650269223 |
| 286 | num_classes = 20 if args.dataset_file != 'coco' else 91 |
| 287 | if args.dataset_file == "coco_panoptic": |
| 288 | # for panoptic, we just add a num_classes that is large enough to hold |
| 289 | # max_obj_id + 1, but the exact value doesn't really matter |
| 290 | num_classes = 250 |
| 291 | device = torch.device(args.device) |
| 292 | |
| 293 | # import pdb;pdb.set_trace() |
| 294 | model = Detector( |
| 295 | num_classes=num_classes, |
| 296 | pre_trained=args.pre_trained, |
| 297 | det_token_num=args.det_token_num, |
| 298 | backbone_name=args.backbone_name, |
| 299 | init_pe_size=args.init_pe_size, |
| 300 | mid_pe_size=args.mid_pe_size, |
| 301 | use_checkpoint=args.use_checkpoint, |
| 302 | |
| 303 | ) |
| 304 | matcher = build_matcher(args) |
| 305 | weight_dict = {'loss_ce': 1, 'loss_bbox': args.bbox_loss_coef} |
| 306 | weight_dict['loss_giou'] = args.giou_loss_coef |
| 307 | # TODO this is a hack |
| 308 | # if args.aux_loss: |
| 309 | # aux_weight_dict = {} |
| 310 | # for i in range(args.dec_layers - 1): |
| 311 | # aux_weight_dict.update({k + f'_{i}': v for k, v in weight_dict.items()}) |
| 312 | # weight_dict.update(aux_weight_dict) |
| 313 | |
| 314 | losses = ['labels', 'boxes', 'cardinality'] |
| 315 | criterion = SetCriterion(num_classes, matcher=matcher, weight_dict=weight_dict, |
| 316 | eos_coef=args.eos_coef, losses=losses) |
| 317 | criterion.to(device) |
| 318 | postprocessors = {'bbox': PostProcess()} |
| 319 | |
| 320 | return model, criterion, postprocessors |
| 321 |
no test coverage detected