MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / D2FocalNet

Class D2FocalNet

semantic_sam/backbone/focal_dw.py:695–776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693
694
695class D2FocalNet(FocalNet, Backbone):
696 def __init__(self, cfg, input_shape):
697
698 pretrain_img_size = cfg['BACKBONE']['FOCAL']['PRETRAIN_IMG_SIZE']
699 patch_size = cfg['BACKBONE']['FOCAL']['PATCH_SIZE']
700 in_chans = 3
701 embed_dim = cfg['BACKBONE']['FOCAL']['EMBED_DIM']
702 depths = cfg['BACKBONE']['FOCAL']['DEPTHS']
703 mlp_ratio = cfg['BACKBONE']['FOCAL']['MLP_RATIO']
704 drop_rate = cfg['BACKBONE']['FOCAL']['DROP_RATE']
705 drop_path_rate = cfg['BACKBONE']['FOCAL']['DROP_PATH_RATE']
706 norm_layer = nn.LayerNorm
707 patch_norm = cfg['BACKBONE']['FOCAL']['PATCH_NORM']
708 use_checkpoint = cfg['BACKBONE']['FOCAL']['USE_CHECKPOINT']
709 out_indices = cfg['BACKBONE']['FOCAL']['OUT_INDICES']
710 scaling_modulator = cfg['BACKBONE']['FOCAL'].get('SCALING_MODULATOR', False)
711
712 super().__init__(
713 pretrain_img_size,
714 patch_size,
715 in_chans,
716 embed_dim,
717 depths,
718 mlp_ratio,
719 drop_rate,
720 drop_path_rate,
721 norm_layer,
722 patch_norm,
723 out_indices,
724 focal_levels=cfg['BACKBONE']['FOCAL']['FOCAL_LEVELS'],
725 focal_windows=cfg['BACKBONE']['FOCAL']['FOCAL_WINDOWS'],
726 use_conv_embed=cfg['BACKBONE']['FOCAL']['USE_CONV_EMBED'],
727 use_postln=cfg['BACKBONE']['FOCAL']['USE_POSTLN'],
728 use_postln_in_modulation=cfg['BACKBONE']['FOCAL']['USE_POSTLN_IN_MODULATION'],
729 scaling_modulator=scaling_modulator,
730 use_layerscale=cfg['BACKBONE']['FOCAL']['USE_LAYERSCALE'],
731 use_checkpoint=use_checkpoint,
732 )
733
734 self._out_features = cfg['BACKBONE']['FOCAL']['OUT_FEATURES']
735
736 self._out_feature_strides = {
737 "res2": 4,
738 "res3": 8,
739 "res4": 16,
740 "res5": 32,
741 }
742 self._out_feature_channels = {
743 "res2": self.num_features[0],
744 "res3": self.num_features[1],
745 "res4": self.num_features[2],
746 "res5": self.num_features[3],
747 }
748
749 def forward(self, x):
750 """
751 Args:
752 x: Tensor of shape (N,C,H,W). H, W must be a multiple of ``self.size_divisibility``.

Callers 1

get_focal_backboneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected