MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / _construct_network

Method _construct_network

slowfast/models/video_model_builder.py:455–600  ·  view source on GitHub ↗

Builds a single pathway ResNet model. Args: cfg (CfgNode): model building configs, details are in the comments of the config file.

(self, cfg)

Source from the content-addressed store, hash-verified

453 )
454
455 def _construct_network(self, cfg):
456 """
457 Builds a single pathway ResNet model.
458
459 Args:
460 cfg (CfgNode): model building configs, details are in the
461 comments of the config file.
462 """
463 assert cfg.MODEL.ARCH in _POOL1.keys()
464 pool_size = _POOL1[cfg.MODEL.ARCH]
465 assert len({len(pool_size), self.num_pathways}) == 1
466 assert cfg.RESNET.DEPTH in _MODEL_STAGE_DEPTH.keys()
467
468 (d2, d3, d4, d5) = _MODEL_STAGE_DEPTH[cfg.RESNET.DEPTH]
469
470 num_groups = cfg.RESNET.NUM_GROUPS
471 width_per_group = cfg.RESNET.WIDTH_PER_GROUP
472 dim_inner = num_groups * width_per_group
473
474 temp_kernel = _TEMPORAL_KERNEL_BASIS[cfg.MODEL.ARCH]
475
476 self.s1 = stem_helper.VideoModelStem(
477 dim_in=cfg.DATA.INPUT_CHANNEL_NUM,
478 dim_out=[width_per_group],
479 kernel=[temp_kernel[0][0] + [7, 7]],
480 stride=[[1, 2, 2]],
481 padding=[[temp_kernel[0][0][0] // 2, 3, 3]],
482 norm_module=self.norm_module,
483 )
484
485 self.s2 = resnet_helper.ResStage(
486 dim_in=[width_per_group],
487 dim_out=[width_per_group * 4],
488 dim_inner=[dim_inner],
489 temp_kernel_sizes=temp_kernel[1],
490 stride=cfg.RESNET.SPATIAL_STRIDES[0],
491 num_blocks=[d2],
492 num_groups=[num_groups],
493 num_block_temp_kernel=cfg.RESNET.NUM_BLOCK_TEMP_KERNEL[0],
494 nonlocal_inds=cfg.NONLOCAL.LOCATION[0],
495 nonlocal_group=cfg.NONLOCAL.GROUP[0],
496 nonlocal_pool=cfg.NONLOCAL.POOL[0],
497 instantiation=cfg.NONLOCAL.INSTANTIATION,
498 trans_func_name=cfg.RESNET.TRANS_FUNC,
499 stride_1x1=cfg.RESNET.STRIDE_1X1,
500 inplace_relu=cfg.RESNET.INPLACE_RELU,
501 dilation=cfg.RESNET.SPATIAL_DILATIONS[0],
502 norm_module=self.norm_module,
503 )
504
505 for pathway in range(self.num_pathways):
506 pool = nn.MaxPool3d(
507 kernel_size=pool_size[pathway],
508 stride=pool_size[pathway],
509 padding=[0, 0, 0],
510 )
511 self.add_module("pathway{}_pool".format(pathway), pool)
512

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected