Builds a single pathway ResNet model. Args: cfg (CfgNode): model building configs, details are in the comments of the config file.
(self, cfg)
| 85 | self._construct_network(cfg) |
| 86 | |
| 87 | def _construct_network(self, cfg): |
| 88 | """ |
| 89 | Builds a single pathway ResNet model. |
| 90 | |
| 91 | Args: |
| 92 | cfg (CfgNode): model building configs, details are in the |
| 93 | comments of the config file. |
| 94 | """ |
| 95 | |
| 96 | # Params from configs. |
| 97 | norm_module = get_norm(cfg) |
| 98 | head_act = get_head_act(cfg.MODEL.HEAD_ACT) |
| 99 | pool_size = _POOL1[cfg.MODEL.ARCH] |
| 100 | num_groups = cfg.RESNET.NUM_GROUPS |
| 101 | spatial_dilations = cfg.RESNET.SPATIAL_DILATIONS |
| 102 | spatial_strides = cfg.RESNET.SPATIAL_STRIDES |
| 103 | temp_kernel = _TEMPORAL_KERNEL_BASIS[cfg.MODEL.ARCH] |
| 104 | stage1_pool = pool_size[0][0] != 1 or len(set(pool_size[0])) > 1 |
| 105 | stage_spatial_stride = ( |
| 106 | spatial_strides[0][0], |
| 107 | spatial_strides[1][0], |
| 108 | spatial_strides[2][0], |
| 109 | spatial_strides[3][0], |
| 110 | ) |
| 111 | if cfg.MODEL.ARCH == "i3d": |
| 112 | stage_conv_a_kernel_size = ( |
| 113 | (3, 1, 1), |
| 114 | [(3, 1, 1), (1, 1, 1)], |
| 115 | [(3, 1, 1), (1, 1, 1)], |
| 116 | [(1, 1, 1), (3, 1, 1)], |
| 117 | ) |
| 118 | else: |
| 119 | stage_conv_a_kernel_size = ( |
| 120 | (temp_kernel[1][0][0], 1, 1), |
| 121 | (temp_kernel[2][0][0], 1, 1), |
| 122 | (temp_kernel[3][0][0], 1, 1), |
| 123 | (temp_kernel[4][0][0], 1, 1), |
| 124 | ) |
| 125 | |
| 126 | # Head from config |
| 127 | if cfg.DETECTION.ENABLE: |
| 128 | # self.detection_head = create_res_roi_pooling_head( |
| 129 | # in_features=cfg.RESNET.WIDTH_PER_GROUP * 2 ** (4 + 1), |
| 130 | # out_features=cfg.MODEL.NUM_CLASSES, |
| 131 | # pool=nn.AvgPool3d, |
| 132 | # output_size=(1, 1, 1), |
| 133 | # pool_kernel_size=( |
| 134 | # cfg.DATA.NUM_FRAMES // pool_size[0][0], |
| 135 | # 1, |
| 136 | # 1, |
| 137 | # ), |
| 138 | # dropout_rate=cfg.MODEL.DROPOUT_RATE, |
| 139 | # activation=None, |
| 140 | # output_with_global_average=False, |
| 141 | # pool_spatial=nn.MaxPool2d, |
| 142 | # resolution=[cfg.DETECTION.ROI_XFORM_RESOLUTION] * 2, |
| 143 | # spatial_scale=1.0 / float(cfg.DETECTION.SPATIAL_SCALE_FACTOR), |
| 144 | # sampling_ratio=0, |
no test coverage detected