235def build_effnet_backbone(cfg):
236
237 pretrain = cfg.MODEL.BACKBONE.PRETRAIN
238 pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
239 last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
240 bn_norm = cfg.MODEL.BACKBONE.NORM
241 depth = cfg.MODEL.BACKBONE.DEPTH
242
243
244 cfg_files = {
245 'b0': 'fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml',
246 'b1': 'fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml',
247 'b2': 'fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml',
248 'b3': 'fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml',
249 'b4': 'fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml',
250 'b5': 'fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml',
251 }[depth]
252
253 effnet_cfg.merge_from_file(cfg_files)
254 model = EffNet(last_stride, bn_norm)
255
256 if pretrain:
257
258 if pretrain_path:
259 try:
260 state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))
261 logger.info(f"Loading pretrained model from {pretrain_path}")
262 except FileNotFoundError as e:
263 logger.info(f'{pretrain_path} is not found! Please check this path.')
264 raise e
265 except KeyError as e:
266 logger.info("State dict keys error! Please check the state dict.")
267 raise e
268 else:
269 key = depth
270 state_dict = init_pretrained_weights(key)
271
272 incompatible = model.load_state_dict(state_dict, strict=False)
273 if incompatible.missing_keys:
274 logger.info(
275 get_missing_parameters_message(incompatible.missing_keys)
276 )
277 if incompatible.unexpected_keys:
278 logger.info(
279 get_unexpected_parameters_message(incompatible.unexpected_keys)
280 )
281 return model