__init__.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from .dilated_encoder import DilatedEncoder
  2. from .hybrid_encoder import HybridEncoder
  3. from .fpn import BasicFPN
  4. from .spp import SPPF
  5. # build neck
  6. def build_neck(cfg, in_dim, out_dim):
  7. print('==============================')
  8. print('Neck: {}'.format(cfg['neck']))
  9. # ----------------------- Neck module -----------------------
  10. if cfg['neck'] == 'dilated_encoder':
  11. model = DilatedEncoder(in_dim = in_dim,
  12. out_dim = out_dim,
  13. expand_ratio = cfg['neck_expand_ratio'],
  14. dilations = cfg['neck_dilations'],
  15. act_type = cfg['neck_act'],
  16. norm_type = cfg['neck_norm']
  17. )
  18. elif cfg['neck'] == 'spp_block':
  19. model = SPPF(in_dim = in_dim,
  20. out_dim = out_dim,
  21. expand_ratio = cfg['neck_expand_ratio'],
  22. pooling_size = cfg["spp_pooling_size"],
  23. act_type = cfg['neck_act'],
  24. norm_type = cfg['neck_norm']
  25. )
  26. # ----------------------- FPN Neck -----------------------
  27. elif cfg['neck'] == 'basic_fpn':
  28. model = BasicFPN(in_dims = in_dim,
  29. out_dim = out_dim,
  30. p6_feat = cfg['fpn_p6_feat'],
  31. p7_feat = cfg['fpn_p7_feat'],
  32. from_c5 = cfg['fpn_p6_from_c5'],
  33. )
  34. elif cfg['neck'] == 'hybrid_encoder':
  35. return HybridEncoder(in_dims = in_dim,
  36. out_dim = out_dim,
  37. num_blocks = cfg['fpn_num_blocks'],
  38. expansion = cfg['fpn_expansion'],
  39. act_type = cfg['fpn_act'],
  40. norm_type = cfg['fpn_norm'],
  41. depthwise = cfg['fpn_depthwise'],
  42. num_heads = cfg['en_num_heads'],
  43. num_layers = cfg['en_num_layers'],
  44. ffn_dim = cfg['en_ffn_dim'],
  45. dropout = cfg['en_dropout'],
  46. pe_temperature = cfg['pe_temperature'],
  47. en_act_type = cfg['en_act'],
  48. en_pre_norm = cfg['en_pre_norm'],
  49. )
  50. else:
  51. raise NotImplementedError("Unknown PaFPN: <{}>".format(cfg['fpn']))
  52. return model