SlowFast model builder for SlowFast network. Christoph Feichtenhofer, Haoqi Fan, Jitendra Malik, and Kaiming He. "SlowFast networks for video recognition." https://arxiv.org/pdf/1812.03982.pdf
| 155 | |
| 156 | @MODEL_REGISTRY.register() |
| 157 | class SlowFast(nn.Module): |
| 158 | """ |
| 159 | SlowFast model builder for SlowFast network. |
| 160 | |
| 161 | Christoph Feichtenhofer, Haoqi Fan, Jitendra Malik, and Kaiming He. |
| 162 | "SlowFast networks for video recognition." |
| 163 | https://arxiv.org/pdf/1812.03982.pdf |
| 164 | """ |
| 165 | |
| 166 | def __init__(self, cfg): |
| 167 | """ |
| 168 | The `__init__` method of any subclass should also contain these |
| 169 | arguments. |
| 170 | Args: |
| 171 | cfg (CfgNode): model building configs, details are in the |
| 172 | comments of the config file. |
| 173 | """ |
| 174 | super(SlowFast, self).__init__() |
| 175 | self.norm_module = get_norm(cfg) |
| 176 | self.enable_detection = cfg.DETECTION.ENABLE |
| 177 | self.num_pathways = 2 |
| 178 | self._construct_network(cfg) |
| 179 | init_helper.init_weights( |
| 180 | self, cfg.MODEL.FC_INIT_STD, cfg.RESNET.ZERO_INIT_FINAL_BN |
| 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], |
nothing calls this directly
no outgoing calls
no test coverage detected