| 597 | |
| 598 | class D2FocalNet(FocalNet, Backbone): |
| 599 | def __init__(self, cfg, input_shape): |
| 600 | |
| 601 | pretrain_img_size = cfg['BACKBONE']['FOCAL']['PRETRAIN_IMG_SIZE'] |
| 602 | patch_size = cfg['BACKBONE']['FOCAL']['PATCH_SIZE'] |
| 603 | in_chans = 3 |
| 604 | embed_dim = cfg['BACKBONE']['FOCAL']['EMBED_DIM'] |
| 605 | depths = cfg['BACKBONE']['FOCAL']['DEPTHS'] |
| 606 | mlp_ratio = cfg['BACKBONE']['FOCAL']['MLP_RATIO'] |
| 607 | drop_rate = cfg['BACKBONE']['FOCAL']['DROP_RATE'] |
| 608 | drop_path_rate = cfg['BACKBONE']['FOCAL']['DROP_PATH_RATE'] |
| 609 | norm_layer = nn.LayerNorm |
| 610 | patch_norm = cfg['BACKBONE']['FOCAL']['PATCH_NORM'] |
| 611 | use_checkpoint = cfg['BACKBONE']['FOCAL']['USE_CHECKPOINT'] |
| 612 | out_indices = cfg['BACKBONE']['FOCAL']['OUT_INDICES'] |
| 613 | scaling_modulator = cfg['BACKBONE']['FOCAL'].get('SCALING_MODULATOR', False) |
| 614 | |
| 615 | super().__init__( |
| 616 | pretrain_img_size, |
| 617 | patch_size, |
| 618 | in_chans, |
| 619 | embed_dim, |
| 620 | depths, |
| 621 | mlp_ratio, |
| 622 | drop_rate, |
| 623 | drop_path_rate, |
| 624 | norm_layer, |
| 625 | patch_norm, |
| 626 | out_indices, |
| 627 | focal_levels=cfg['BACKBONE']['FOCAL']['FOCAL_LEVELS'], |
| 628 | focal_windows=cfg['BACKBONE']['FOCAL']['FOCAL_WINDOWS'], |
| 629 | use_conv_embed=cfg['BACKBONE']['FOCAL']['USE_CONV_EMBED'], |
| 630 | use_postln=cfg['BACKBONE']['FOCAL']['USE_POSTLN'], |
| 631 | use_postln_in_modulation=cfg['BACKBONE']['FOCAL']['USE_POSTLN_IN_MODULATION'], |
| 632 | scaling_modulator=scaling_modulator, |
| 633 | use_layerscale=cfg['BACKBONE']['FOCAL']['USE_LAYERSCALE'], |
| 634 | use_checkpoint=use_checkpoint, |
| 635 | ) |
| 636 | |
| 637 | self._out_features = cfg['BACKBONE']['FOCAL']['OUT_FEATURES'] |
| 638 | |
| 639 | self._out_feature_strides = { |
| 640 | "res2": 4, |
| 641 | "res3": 8, |
| 642 | "res4": 16, |
| 643 | "res5": 32, |
| 644 | } |
| 645 | self._out_feature_channels = { |
| 646 | "res2": self.num_features[0], |
| 647 | "res3": self.num_features[1], |
| 648 | "res4": self.num_features[2], |
| 649 | "res5": self.num_features[3], |
| 650 | } |
| 651 | |
| 652 | def forward(self, x): |
| 653 | """ |