Builds a SlowFast model. Args: cfg (CfgNode): model building configs, details are in the comments of the config file.
(self, cfg)
| 243 | self._construct_network(cfg) |
| 244 | |
| 245 | def _construct_network(self, cfg): |
| 246 | """ |
| 247 | Builds a SlowFast model. |
| 248 | |
| 249 | Args: |
| 250 | cfg (CfgNode): model building configs, details are in the |
| 251 | comments of the config file. |
| 252 | """ |
| 253 | _MODEL_STAGE_DEPTH = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3)} |
| 254 | |
| 255 | # Params from configs. |
| 256 | norm_module = get_norm(cfg) |
| 257 | pool_size = _POOL1[cfg.MODEL.ARCH] |
| 258 | num_groups = cfg.RESNET.NUM_GROUPS |
| 259 | width_per_group = cfg.RESNET.WIDTH_PER_GROUP |
| 260 | spatial_dilations = cfg.RESNET.SPATIAL_DILATIONS |
| 261 | spatial_strides = cfg.RESNET.SPATIAL_STRIDES |
| 262 | temp_kernel = _TEMPORAL_KERNEL_BASIS[cfg.MODEL.ARCH] |
| 263 | num_block_temp_kernel = cfg.RESNET.NUM_BLOCK_TEMP_KERNEL |
| 264 | stage_depth = _MODEL_STAGE_DEPTH[cfg.RESNET.DEPTH] |
| 265 | |
| 266 | stage_conv_a_kernel_sizes = [[], []] |
| 267 | for pathway in range(2): |
| 268 | for stage in range(4): |
| 269 | stage_conv_a_kernel_sizes[pathway].append( |
| 270 | ((temp_kernel[stage + 1][pathway][0], 1, 1),) |
| 271 | * num_block_temp_kernel[stage][pathway] |
| 272 | + ((1, 1, 1),) |
| 273 | * ( |
| 274 | stage_depth[stage] |
| 275 | - num_block_temp_kernel[stage][pathway] |
| 276 | ) |
| 277 | ) |
| 278 | |
| 279 | # Head from config |
| 280 | # Number of stages = 4 |
| 281 | stage_dim_in = cfg.RESNET.WIDTH_PER_GROUP * 2 ** (4 + 1) |
| 282 | head_in_features = stage_dim_in |
| 283 | for reduction_ratio in cfg.SLOWFAST.BETA_INV: |
| 284 | head_in_features = ( |
| 285 | head_in_features + stage_dim_in // reduction_ratio |
| 286 | ) |
| 287 | |
| 288 | if cfg.DETECTION.ENABLE: |
| 289 | # self.detection_head = create_res_roi_pooling_head( |
| 290 | # in_features=head_in_features, |
| 291 | # out_features=cfg.MODEL.NUM_CLASSES, |
| 292 | # pool=None, |
| 293 | # output_size=(1, 1, 1), |
| 294 | # dropout_rate=cfg.MODEL.DROPOUT_RATE, |
| 295 | # activation=None, |
| 296 | # output_with_global_average=False, |
| 297 | # pool_spatial=nn.MaxPool2d, |
| 298 | # resolution=[cfg.DETECTION.ROI_XFORM_RESOLUTION] * 2, |
| 299 | # spatial_scale=1.0 / float(cfg.DETECTION.SPATIAL_SCALE_FACTOR), |
| 300 | # sampling_ratio=0, |
| 301 | # roi=ROIAlign, |
| 302 | # ) |
no test coverage detected