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

Class PTVSlowFast

slowfast/models/ptv_model_builder.py:223–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221
222@MODEL_REGISTRY.register()
223class PTVSlowFast(nn.Module):
224 def __init__(self, cfg):
225 """
226 The `__init__` method of any subclass should also contain these
227 arguments.
228
229 Args:
230 cfg (CfgNode): model building configs, details are in the
231 comments of the config file.
232 """
233 super(PTVSlowFast, self).__init__()
234
235 assert (
236 cfg.RESNET.STRIDE_1X1 is False
237 ), "STRIDE_1x1 must be True for PTVSlowFast"
238 assert (
239 cfg.RESNET.TRANS_FUNC == "bottleneck_transform"
240 ), f"Unsupported TRANS_FUNC type {cfg.RESNET.TRANS_FUNC} for PTVSlowFast"
241
242 self.detection_mode = cfg.DETECTION.ENABLE
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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected