542def build_regnet_backbone(cfg):
543
544 pretrain = cfg.MODEL.BACKBONE.PRETRAIN
545 pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
546 last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
547 bn_norm = cfg.MODEL.BACKBONE.NORM
548 depth = cfg.MODEL.BACKBONE.DEPTH
549
550
551 cfg_files = {
552 '800x': 'fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml',
553 '800y': 'fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml',
554 '1600x': 'fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml',
555 '1600y': 'fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml',
556 '3200x': 'fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml',
557 '3200y': 'fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml',
558 '4000x': 'fastreid/modeling/backbones/regnet/regnety/RegNetX-4.0GF_dds_8gpu.yaml',
559 '4000y': 'fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml',
560 '6400x': 'fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml',
561 '6400y': 'fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml',
562 }[depth]
563
564 regnet_cfg.merge_from_file(cfg_files)
565 model = RegNet(last_stride, bn_norm)
566
567 if pretrain:
568
569 if pretrain_path:
570 try:
571 state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))
572 logger.info(f"Loading pretrained model from {pretrain_path}")
573 except FileNotFoundError as e:
574 logger.info(f'{pretrain_path} is not found! Please check this path.')
575 raise e
576 except KeyError as e:
577 logger.info("State dict keys error! Please check the state dict.")
578 raise e
579 else:
580 key = depth
581 state_dict = init_pretrained_weights(key)
582
583 incompatible = model.load_state_dict(state_dict, strict=False)
584 if incompatible.missing_keys:
585 logger.info(
586 get_missing_parameters_message(incompatible.missing_keys)
587 )
588 if incompatible.unexpected_keys:
589 logger.info(
590 get_unexpected_parameters_message(incompatible.unexpected_keys)
591 )
592 return model