Builds a SlowFast model. The first pathway is the Slow pathway and the second pathway is the Fast pathway. Args: cfg (CfgNode): model building configs, details are in the comments of the config file.
(self, cfg)
| 181 | ) |
| 182 | |
| 183 | def _construct_network(self, cfg): |
| 184 | """ |
| 185 | Builds a SlowFast model. The first pathway is the Slow pathway and the |
| 186 | second pathway is the Fast pathway. |
| 187 | Args: |
| 188 | cfg (CfgNode): model building configs, details are in the |
| 189 | comments of the config file. |
| 190 | """ |
| 191 | assert cfg.MODEL.ARCH in _POOL1.keys() |
| 192 | pool_size = _POOL1[cfg.MODEL.ARCH] |
| 193 | assert len({len(pool_size), self.num_pathways}) == 1 |
| 194 | assert cfg.RESNET.DEPTH in _MODEL_STAGE_DEPTH.keys() |
| 195 | |
| 196 | (d2, d3, d4, d5) = _MODEL_STAGE_DEPTH[cfg.RESNET.DEPTH] |
| 197 | |
| 198 | num_groups = cfg.RESNET.NUM_GROUPS |
| 199 | width_per_group = cfg.RESNET.WIDTH_PER_GROUP |
| 200 | dim_inner = num_groups * width_per_group |
| 201 | out_dim_ratio = ( |
| 202 | cfg.SLOWFAST.BETA_INV // cfg.SLOWFAST.FUSION_CONV_CHANNEL_RATIO |
| 203 | ) |
| 204 | |
| 205 | temp_kernel = _TEMPORAL_KERNEL_BASIS[cfg.MODEL.ARCH] |
| 206 | |
| 207 | self.s1 = stem_helper.VideoModelStem( |
| 208 | dim_in=cfg.DATA.INPUT_CHANNEL_NUM, |
| 209 | dim_out=[width_per_group, width_per_group // cfg.SLOWFAST.BETA_INV], |
| 210 | kernel=[temp_kernel[0][0] + [7, 7], temp_kernel[0][1] + [7, 7]], |
| 211 | stride=[[1, 2, 2]] * 2, |
| 212 | padding=[ |
| 213 | [temp_kernel[0][0][0] // 2, 3, 3], |
| 214 | [temp_kernel[0][1][0] // 2, 3, 3], |
| 215 | ], |
| 216 | norm_module=self.norm_module, |
| 217 | ) |
| 218 | self.s1_fuse = FuseFastToSlow( |
| 219 | width_per_group // cfg.SLOWFAST.BETA_INV, |
| 220 | cfg.SLOWFAST.FUSION_CONV_CHANNEL_RATIO, |
| 221 | cfg.SLOWFAST.FUSION_KERNEL_SZ, |
| 222 | cfg.SLOWFAST.ALPHA, |
| 223 | norm_module=self.norm_module, |
| 224 | ) |
| 225 | |
| 226 | self.s2 = resnet_helper.ResStage( |
| 227 | dim_in=[ |
| 228 | width_per_group + width_per_group // out_dim_ratio, |
| 229 | width_per_group // cfg.SLOWFAST.BETA_INV, |
| 230 | ], |
| 231 | dim_out=[ |
| 232 | width_per_group * 4, |
| 233 | width_per_group * 4 // cfg.SLOWFAST.BETA_INV, |
| 234 | ], |
| 235 | dim_inner=[dim_inner, dim_inner // cfg.SLOWFAST.BETA_INV], |
| 236 | temp_kernel_sizes=temp_kernel[1], |
| 237 | stride=cfg.RESNET.SPATIAL_STRIDES[0], |
| 238 | num_blocks=[d2] * 2, |
| 239 | num_groups=[num_groups] * 2, |
| 240 | num_block_temp_kernel=cfg.RESNET.NUM_BLOCK_TEMP_KERNEL[0], |