Spaces:
Sleeping
Sleeping
File size: 19,166 Bytes
749745d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
from collections import OrderedDict
from torch import nn
from maskrcnn_benchmark.modeling import registry
from maskrcnn_benchmark.modeling.make_layers import conv_with_kaiming_uniform
from maskrcnn_benchmark.layers import DropBlock2D, DyHead
from . import fpn as fpn_module
from . import bifpn
from . import resnet
from . import efficientnet
from . import efficientdet
from . import swint
from . import swint_v2
from . import swint_vl
from . import swint_v2_vl
from . import fusion_swin_transformer
from . import fusion_swin_transformer_v2
from . import fusion_swin_transformer_v3
@registry.BACKBONES.register("R-50-C4")
@registry.BACKBONES.register("R-50-C5")
@registry.BACKBONES.register("R-101-C4")
@registry.BACKBONES.register("R-101-C5")
def build_resnet_backbone(cfg):
body = resnet.ResNet(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.BACKBONES.register("R-50-RETINANET")
@registry.BACKBONES.register("R-101-RETINANET")
def build_resnet_c5_backbone(cfg):
body = resnet.ResNet(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.BACKBONES.register("R-34-v2-RETINANET")
@registry.BACKBONES.register("R-34-v2-FCOS")
def build_mobile_backbone(cfg):
body = resnet_light_v2.ResNetC5(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.BACKBONES.register("R-34-v2-FPN")
def build_resnet_fpn_backbone(cfg):
body = resnet_light_v2.ResNet(cfg)
in_channels_stage2 = 64
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
fpn = fpn_module.FPN(
in_channels_list=[
in_channels_stage2,
in_channels_stage2 * 2,
in_channels_stage2 * 4,
in_channels_stage2 * 8,
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU, cfg.MODEL.FPN.USE_DYRELU),
top_blocks=fpn_module.LastLevelMaxPool(),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("R-34-v2-FPN-RETINANET")
@registry.BACKBONES.register("R-34-v2-FPN-FCOS")
def build_resnet_light_fpn_p6p7_backbone(cfg):
body = resnet_light_v2.ResNet(cfg)
in_channels_stage2 = 64
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
fpn = fpn_module.FPN(
in_channels_list=[
0,
in_channels_stage2 * 2,
in_channels_stage2 * 4,
in_channels_stage2 * 8,
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU, cfg.MODEL.FPN.USE_DYRELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("R-50-FPN")
@registry.BACKBONES.register("R-101-FPN")
def build_resnet_fpn_backbone(cfg):
body = resnet_evo.ResNet(cfg) if cfg.MODEL.BACKBONE.USE_EN else resnet.ResNet(cfg)
in_channels_stage2 = cfg.MODEL.RESNETS.RES2_OUT_CHANNELS
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
fpn = fpn_module.FPN(
in_channels_list=[
in_channels_stage2,
in_channels_stage2 * 2,
in_channels_stage2 * 4,
in_channels_stage2 * 8,
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelMaxPool(),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
if cfg.MODEL.FPN.USE_DYHEAD:
dyhead = DyHead(cfg, out_channels)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn), ("dyhead", dyhead)]))
else:
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("R-50-FPN-RETINANET")
@registry.BACKBONES.register("R-101-FPN-RETINANET")
@registry.BACKBONES.register("R-50-FPN-FCOS")
@registry.BACKBONES.register("R-101-FPN-FCOS")
def build_resnet_fpn_p6p7_backbone(cfg):
body = resnet_evo.ResNet(cfg) if cfg.MODEL.BACKBONE.USE_EN else resnet.ResNet(cfg)
in_channels_stage2 = cfg.MODEL.RESNETS.RES2_OUT_CHANNELS
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
fpn = fpn_module.FPN(
in_channels_list=[
0,
in_channels_stage2 * 2,
in_channels_stage2 * 4,
in_channels_stage2 * 8,
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("SWINT-FPN-RETINANET")
def build_retinanet_swint_fpn_backbone(cfg):
"""
Args:
cfg: a detectron2 CfgNode
Returns:
backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
"""
if cfg.MODEL.SWINT.VERSION == "v1":
body = swint.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "v2":
body = swint_v2.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "vl":
body = swint_vl.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "v2_vl":
body = swint_v2_vl.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "fusion" and cfg.MODEL.BACKBONE.FUSION_VERSION == "v1":
body = fusion_swin_transformer.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "fusion" and cfg.MODEL.BACKBONE.FUSION_VERSION == "v2":
body = fusion_swin_transformer_v2.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "fusion" and cfg.MODEL.BACKBONE.FUSION_VERSION == "v3":
body = fusion_swin_transformer_v3.build_swint_backbone(cfg)
in_channels_stages = cfg.MODEL.SWINT.OUT_CHANNELS
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
fpn = fpn_module.FPN(
in_channels_list=[
0,
in_channels_stages[-3],
in_channels_stages[-2],
in_channels_stages[-1],
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
return_swint_feature_before_fusion=cfg.MODEL.FPN.RETURN_SWINT_FEATURE_BEFORE_FUSION,
)
if cfg.MODEL.FPN.USE_DYHEAD:
dyhead = DyHead(cfg, out_channels)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn), ("dyhead", dyhead)]))
else:
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("SWINT-FPN")
def build_swint_fpn_backbone(cfg):
"""
Args:
cfg: a detectron2 CfgNode
Returns:
backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
"""
if cfg.MODEL.SWINT.VERSION == "v1":
body = swint.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "v2":
body = swint_v2.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "vl":
body = swint_vl.build_swint_backbone(cfg)
elif cfg.MODEL.SWINT.VERSION == "v2_vl":
body = swint_v2_vl.build_swint_backbone(cfg)
in_channels_stages = cfg.MODEL.SWINT.OUT_CHANNELS
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
fpn = fpn_module.FPN(
in_channels_list=[
in_channels_stages[-4],
in_channels_stages[-3],
in_channels_stages[-2],
in_channels_stages[-1],
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelMaxPool(),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
if cfg.MODEL.FPN.USE_DYHEAD:
dyhead = DyHead(cfg, out_channels)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn), ("dyhead", dyhead)]))
else:
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("CVT-FPN-RETINANET")
def build_retinanet_cvt_fpn_backbone(cfg):
"""
Args:
cfg: a detectron2 CfgNode
Returns:
backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
"""
body = cvt.build_cvt_backbone(cfg)
in_channels_stages = cfg.MODEL.SPEC.DIM_EMBED
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
fpn = fpn_module.FPN(
in_channels_list=[
0,
in_channels_stages[-3],
in_channels_stages[-2],
in_channels_stages[-1],
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
if cfg.MODEL.FPN.USE_DYHEAD:
dyhead = DyHead(cfg, out_channels)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn), ("dyhead", dyhead)]))
else:
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("CVT-FPN")
def build_cvt_fpn_backbone(cfg):
"""
Args:
cfg: a detectron2 CfgNode
Returns:
backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
"""
body = cvt.build_cvt_backbone(cfg)
in_channels_stages = cfg.MODEL.SPEC.DIM_EMBED
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
fpn = fpn_module.FPN(
in_channels_list=[
in_channels_stages[-4],
in_channels_stages[-3],
in_channels_stages[-2],
in_channels_stages[-1],
],
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelMaxPool(),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
if cfg.MODEL.FPN.USE_DYHEAD:
dyhead = DyHead(cfg, out_channels)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn), ("dyhead", dyhead)]))
else:
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("BigR50x3-FPN-RETINANET")
@registry.BACKBONES.register("BigR50x3-FPN-FCOS")
@registry.BACKBONES.register("BigR101x3-FPN-RETINANET")
@registry.BACKBONES.register("BigR101x3-FPN-FCOS")
@registry.BACKBONES.register("BigR152x4-FPN-RETINANET")
@registry.BACKBONES.register("BigR152x4-FPN-FCOS")
def build_resnet_fpn_p6p7_backbone(cfg):
version = cfg.MODEL.BACKBONE.CONV_BODY.split("-")[0]
body = resnet_big.BIG_MODELS[version](cfg)
in_channels_stage = body.out_channels
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
in_channels_stage[0] = 0
fpn = fpn_module.FPN(
in_channels_list=in_channels_stage,
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("NAS-RETINANET")
def build_nas_backbone(cfg):
body = nas.Net(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.BACKBONES.register("NAS-FPN")
def build_nas_backbone(cfg):
body = nas.SingpathSupernet(cfg) if cfg.MODEL.META_ARCHITECTURE == "SupernetRCNN" else nas.Net(cfg)
in_channels_stage = body.out_channels
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
fpn = fpn_module.FPN(
in_channels_list=in_channels_stage,
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelMaxPool(),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("NAS-FPN-RETINANET")
@registry.BACKBONES.register("NAS-FPN-FCOS")
def build_resnet_light_fpn_p6p7_backbone(cfg):
body = nas.SingpathSupernet(cfg) if cfg.MODEL.META_ARCHITECTURE == "SupernetRCNN" else nas.Net(cfg)
in_channels_stage = body.out_channels
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
in_channels_stage[0] = 0
fpn = fpn_module.FPN(
in_channels_list=in_channels_stage,
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("EFFICIENT7-FPN-RETINANET")
@registry.BACKBONES.register("EFFICIENT7-FPN-FCOS")
@registry.BACKBONES.register("EFFICIENT5-FPN-RETINANET")
@registry.BACKBONES.register("EFFICIENT5-FPN-FCOS")
@registry.BACKBONES.register("EFFICIENT3-FPN-RETINANET")
@registry.BACKBONES.register("EFFICIENT3-FPN-FCOS")
def build_eff_fpn_p6p7_backbone(cfg):
version = cfg.MODEL.BACKBONE.CONV_BODY.split("-")[0]
version = version.replace("EFFICIENT", "b")
body = efficientnet.get_efficientnet(cfg, version)
in_channels_stage = body.out_channels
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
in_channels_p6p7 = out_channels
in_channels_stage[0] = 0
fpn = fpn_module.FPN(
in_channels_list=in_channels_stage,
out_channels=out_channels,
conv_block=conv_with_kaiming_uniform(cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU),
top_blocks=fpn_module.LastLevelP6P7(in_channels_p6p7, out_channels),
drop_block=DropBlock2D(cfg.MODEL.FPN.DROP_PROB, cfg.MODEL.FPN.DROP_SIZE) if cfg.MODEL.FPN.DROP_BLOCK else None,
use_spp=cfg.MODEL.FPN.USE_SPP,
use_pan=cfg.MODEL.FPN.USE_PAN,
)
model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)]))
return model
@registry.BACKBONES.register("EFFICIENT7-BIFPN-RETINANET")
@registry.BACKBONES.register("EFFICIENT7-BIFPN-FCOS")
@registry.BACKBONES.register("EFFICIENT5-BIFPN-RETINANET")
@registry.BACKBONES.register("EFFICIENT5-BIFPN-FCOS")
@registry.BACKBONES.register("EFFICIENT3-BIFPN-RETINANET")
@registry.BACKBONES.register("EFFICIENT3-BIFPN-FCOS")
def build_eff_fpn_p6p7_backbone(cfg):
version = cfg.MODEL.BACKBONE.CONV_BODY.split("-")[0]
version = version.replace("EFFICIENT", "b")
body = efficientnet.get_efficientnet(cfg, version)
in_channels_stage = body.out_channels
out_channels = cfg.MODEL.BACKBONE.OUT_CHANNELS
bifpns = nn.ModuleList()
for i in range(cfg.MODEL.BIFPN.NUM_REPEATS):
first_time = i == 0
fpn = bifpn.BiFPN(
in_channels_list=in_channels_stage[1:],
out_channels=out_channels,
first_time=first_time,
attention=cfg.MODEL.BIFPN.USE_ATTENTION,
)
bifpns.append(fpn)
model = nn.Sequential(OrderedDict([("body", body), ("bifpn", bifpns)]))
return model
@registry.BACKBONES.register("EFFICIENT-DET")
def build_efficientdet_backbone(cfg):
efficientdet.g_simple_padding = True
compound = cfg.MODEL.BACKBONE.EFFICIENT_DET_COMPOUND
start_from = cfg.MODEL.BACKBONE.EFFICIENT_DET_START_FROM
model = efficientdet.EffNetFPN(
compound_coef=compound,
start_from=start_from,
)
if cfg.MODEL.BACKBONE.USE_SYNCBN:
import torch
model = torch.nn.SyncBatchNorm.convert_sync_batchnorm(model)
return model
def build_backbone(cfg):
assert (
cfg.MODEL.BACKBONE.CONV_BODY in registry.BACKBONES
), "cfg.MODEL.BACKBONE.CONV_BODY: {} are not registered in registry".format(cfg.MODEL.BACKBONE.CONV_BODY)
return registry.BACKBONES[cfg.MODEL.BACKBONE.CONV_BODY](cfg)
def build_fusion_backbone(vision_backbone, language_backbone, version, add_linear_layer):
if version == "v1":
return fusion_swin_transformer.build_combined_backbone(vision_backbone, language_backbone, add_linear_layer)
elif version == "v2":
return fusion_swin_transformer_v2.build_combined_backbone(vision_backbone, language_backbone, add_linear_layer)
elif version == "v3":
return fusion_swin_transformer_v3.build_combined_backbone(vision_backbone, language_backbone, add_linear_layer)
|