class_docstr: ResNet_I3D backbone.
  Inflated 3D model (I3D) from
  `"Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset"
  <https://arxiv.org/abs/1705.07750>`_ paper.
  
  Parameters
  ----------
  nclass : int.
      Number of categories in the dataset.
  depth : int, default is 50.
      Depth of ResNet, from {18, 34, 50, 101, 152}.
  num_stages : int, default is 4.
      Number of stages in a ResNet.
  pretrained : bool or str.
      Boolean value controls whether to load the default pretrained weights for model.
      String value represents the hashtag for a certain version of pretrained weights.
  pretrained_base : bool or str, optional, default is True.
      Load pretrained base network, the extra layers are randomized. Note that
      if pretrained is `True`, this has no effect.
  feat_ext : bool.
      Whether to extract features before dense classification layer or
      do a complete forward pass.
  num_segments : int, default is 1.
      Number of segments used to evenly divide a video.
  num_crop : int, default is 1.
      Number of crops used during evaluation, choices are 1, 3 or 10.
  spatial_strides : tuple of int.
      Strides in the spatial dimension of the first block of each stage.
  temporal_strides : tuple of int.
      Strides in the temporal dimension of the first block of each stage.
  dilations : tuple of int.
      Dilation ratio of each stage.
  out_indices : tuple of int.
      Collect features from the selected stages of ResNet,
      usually used for feature extraction or auxililary loss.
  conv1_kernel_t : int, default is 5.
      The kernel size of first convolutional layer in a ResNet.
  conv1_stride_t : int, default is 2.
      The stride of first convolutional layer in a ResNet.
  pool1_kernel_t : int, default is 1.
      The kernel size of first pooling layer in a ResNet.
  pool1_stride_t : int, default is 2.
      The stride of first pooling layer in a ResNet.
  inflate_freq : tuple of int.
      Select which 2D convolutional layers to be inflated to 3D convolutional layers in each stage.
  inflate_stride : tuple of int.
      The stride for inflated layers in each stage.
  inflate_style : str, default is '3x1x1'.
      How to inflate a 2D kernel, either '3x1x1' or '1x3x3'.
  nonlocal_stages : tuple of int.
      Select which stage we need non-local blocks.
  nonlocal_freq : tuple of int.
      Select where to insert non-local blocks in each stage.
  nonlocal_cfg : dict.
      Additional `non-local` arguments, for example `nonlocal_type='gaussian'`.
  bn_eval : bool.
      Whether to set BN layers to eval mode, namely, freeze
      running stats (mean and var).
  bn_frozen : bool.
      Whether to freeze weight and bias of BN layers.
  partial_bn : bool, default False.
      Freeze all batch normalization layers during training except the first layer.
  frozen_stages : int.
      Stages to be frozen (all param fixed). -1 means not freezing any parameters.
  dropout_ratio : float, default is 0.5.
      The dropout rate of a dropout layer.
      The larger the value, the more strength to prevent overfitting.
  init_std : float, default is 0.001.
      Standard deviation value when initialize the dense layers.
  norm_layer : object
      Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
      Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
  norm_kwargs : dict
      Additional `norm_layer` arguments, for example `num_devices=4`
      for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
  ctx : Context, default CPU.
      The context in which to load the pretrained weights.
class_docstr_tok: ["ResNet_I3D","backbone",".","Inflated","3D","model","(","I3D",")","from","`","``","Quo","Vadis",",","Action","Recognition","?","A","New","Model","and","the","Kinetics","Dataset","''","<","https",":","\/\/arxiv.org\/abs\/1705.07750",">","`","_","paper",".","Parameters","--","--","--","--","--","nclass",":","int",".","Number","of","categories","in","the","dataset",".","depth",":","int",",","default","is","50",".","Depth","of","ResNet",",","from","{","18",",","34",",","50",",","101",",","152","}",".","num_stages",":","int",",","default","is","4",".","Number","of","stages","in","a","ResNet",".","pretrained",":","bool","or","str",".","Boolean","value","controls","whether","to","load","the","default","pretrained","weights","for","model",".","String","value","represents","the","hashtag","for","a","certain","version","of","pretrained","weights",".","pretrained_base",":","bool","or","str",",","optional",",","default","is","True",".","Load","pretrained","base","network",",","the","extra","layers","are","randomized",".","Note","that","if","pretrained","is","`","True","`",",","this","has","no","effect",".","feat_ext",":","bool",".","Whether","to","extract","features","before","dense","classification","layer","or","do","a","complete","forward","pass",".","num_segments",":","int",",","default","is","1",".","Number","of","segments","used","to","evenly","divide","a","video",".","num_crop",":","int",",","default","is","1",".","Number","of","crops","used","during","evaluation",",","choices","are","1",",","3","or","10.","spatial_strides",":","tuple","of","int",".","Strides","in","the","spatial","dimension","of","the","first","block","of","each","stage",".","temporal_strides",":","tuple","of","int",".","Strides","in","the","temporal","dimension","of","the","first","block","of","each","stage",".","dilations",":","tuple","of","int",".","Dilation","ratio","of","each","stage",".","out_indices",":","tuple","of","int",".","Collect","features","from","the","selected","stages","of","ResNet",",","usually","used","for","feature","extraction","or","auxililary","loss",".","conv1_kernel_t",":","int",",","default","is","5",".","The","kernel","size","of","first","convolutional","layer","in","a","ResNet",".","conv1_stride_t",":","int",",","default","is","2",".","The","stride","of","first","convolutional","layer","in","a","ResNet",".","pool1_kernel_t",":","int",",","default","is","1",".","The","kernel","size","of","first","pooling","layer","in","a","ResNet",".","pool1_stride_t",":","int",",","default","is","2",".","The","stride","of","first","pooling","layer","in","a","ResNet",".","inflate_freq",":","tuple","of","int",".","Select","which","2D","convolutional","layers","to","be","inflated","to","3D","convolutional","layers","in","each","stage",".","inflate_stride",":","tuple","of","int",".","The","stride","for","inflated","layers","in","each","stage",".","inflate_style",":","str",",","default","is","'3x1x1","'",".","How","to","inflate","a","2D","kernel",",","either","'3x1x1","'","or","'1x3x3","'",".","nonlocal_stages",":","tuple","of","int",".","Select","which","stage","we","need","non-local","blocks",".","nonlocal_freq",":","tuple","of","int",".","Select","where","to","insert","non-local","blocks","in","each","stage",".","nonlocal_cfg",":","dict",".","Additional","`","non-local","`","arguments",",","for","example","`","nonlocal_type='gaussian","'","`",".","bn_eval",":","bool",".","Whether","to","set","BN","layers","to","eval","mode",",","namely",",","freeze","running","stats","(","mean","and","var",")",".","bn_frozen",":","bool",".","Whether","to","freeze","weight","and","bias","of","BN","layers",".","partial_bn",":","bool",",","default","False",".","Freeze","all","batch","normalization","layers","during","training","except","the","first","layer",".","frozen_stages",":","int",".","Stages","to","be","frozen","(","all","param","fixed",")",".","-1","means","not","freezing","any","parameters",".","dropout_ratio",":","float",",","default","is","0.5",".","The","dropout","rate","of","a","dropout","layer",".","The","larger","the","value",",","the","more","strength","to","prevent","overfitting",".","init_std",":","float",",","default","is","0.001",".","Standard","deviation","value","when","initialize","the","dense","layers",".","norm_layer",":","object","Normalization","layer","used","(","default",":",":","class",":","`","mxnet.gluon.nn.BatchNorm","`",")","Can","be",":","class",":","`","mxnet.gluon.nn.BatchNorm","`","or",":","class",":","`","mxnet.gluon.contrib.nn.SyncBatchNorm","`",".","norm_kwargs",":","dict","Additional","`","norm_layer","`","arguments",",","for","example","`","num_devices=4","`","for",":","class",":","`","mxnet.gluon.contrib.nn.SyncBatchNorm","`",".","ctx",":","Context",",","default","CPU",".","The","context","in","which","to","load","the","pretrained","weights","."]
code: def __init__(
      self,
      nclass,
      depth,
      num_stages=4,
      pretrained=False,
      pretrained_base=True,
      feat_ext=False,
      num_segments=1,
      num_crop=1,
      spatial_strides=(1, 2, 2, 2),
      temporal_strides=(1, 1, 1, 1),
      dilations=(1, 1, 1, 1),
      out_indices=(0, 1, 2, 3),
      conv1_kernel_t=5,
      conv1_stride_t=2,
      pool1_kernel_t=1,
      pool1_stride_t=2,
      inflate_freq=(1, 1, 1, 1),
      inflate_stride=(1, 1, 1, 1),
      inflate_style="3x1x1",
      nonlocal_stages=(-1,),
      nonlocal_freq=(0, 1, 1, 0),
      nonlocal_cfg=None,
      bn_eval=True,
      bn_frozen=False,
      partial_bn=False,
      frozen_stages=-1,
      dropout_ratio=0.5,
      init_std=0.01,
      norm_layer=BatchNorm,
      norm_kwargs=None,
      ctx=None,
      **kwargs,
  ):
      super(I3D_ResNetV1, self).__init__()
  
      if depth not in self.arch_settings:
          raise KeyError("invalid depth {} for resnet".format(depth))
  
      self.nclass = nclass
      self.depth = depth
      self.num_stages = num_stages
      self.pretrained = pretrained
      self.pretrained_base = pretrained_base
      self.feat_ext = feat_ext
      self.num_segments = num_segments
      self.num_crop = num_crop
      self.spatial_strides = spatial_strides
      self.temporal_strides = temporal_strides
      self.dilations = dilations
      assert (
          len(spatial_strides)
          == len(temporal_strides)
          == len(dilations)
          == num_stages
      )
      self.out_indices = out_indices
      assert max(out_indices) < num_stages
      self.inflate_freqs = (
          inflate_freq
          if not isinstance(inflate_freq, int)
          else (inflate_freq,) * num_stages
      )
      self.inflate_style = inflate_style
      self.nonlocal_stages = nonlocal_stages
      self.nonlocal_freqs = (
          nonlocal_freq
          if not isinstance(nonlocal_freq, int)
          else (nonlocal_freq,) * num_stages
      )
      self.nonlocal_cfg = nonlocal_cfg
      self.bn_eval = bn_eval
      self.bn_frozen = bn_frozen
      self.partial_bn = partial_bn
      self.frozen_stages = frozen_stages
      self.dropout_ratio = dropout_ratio
      self.init_std = init_std
  
      self.block, stage_blocks = self.arch_settings[depth]
      self.stage_blocks = stage_blocks[:num_stages]
      self.inplanes = 64
  
      if self.bn_frozen:
          if norm_kwargs is not None:
              norm_kwargs["use_global_stats"] = True
          else:
              norm_kwargs = {}
              norm_kwargs["use_global_stats"] = True
  
      self.first_stage = nn.HybridSequential(prefix="")
      self.first_stage.add(
          nn.Conv3D(
              in_channels=3,
              channels=64,
              kernel_size=(conv1_kernel_t, 7, 7),
              strides=(conv1_stride_t, 2, 2),
              padding=((conv1_kernel_t - 1) // 2, 3, 3),
              use_bias=False,
          )
      )
      self.first_stage.add(
          norm_layer(
              in_channels=64,
              **({} if norm_kwargs is None else norm_kwargs),
          )
      )
      self.first_stage.add(nn.Activation("relu"))
      self.first_stage.add(
          nn.MaxPool3D(
              pool_size=(pool1_kernel_t, 3, 3),
              strides=(pool1_stride_t, 2, 2),
              padding=(pool1_kernel_t // 2, 1, 1),
          )
      )
  
      self.pool2 = nn.MaxPool3D(
          pool_size=(2, 1, 1), strides=(2, 1, 1), padding=(0, 0, 0)
      )
  
      if self.partial_bn:
          if norm_kwargs is not None:
              norm_kwargs["use_global_stats"] = True
          else:
              norm_kwargs = {}
              norm_kwargs["use_global_stats"] = True
  
      self.res_layers = nn.HybridSequential(prefix="")
      for i, num_blocks in enumerate(self.stage_blocks):
          spatial_stride = spatial_strides[i]
          temporal_stride = temporal_strides[i]
          dilation = dilations[i]
          planes = 64 * 2**i
          layer_name = "layer{}_".format(i + 1)
  
          res_layer = make_res_layer(
              self.block,
              self.inplanes,
              planes,
              num_blocks,
              spatial_stride=spatial_stride,
              temporal_stride=temporal_stride,
              dilation=dilation,
              inflate_freq=self.inflate_freqs[i],
              inflate_style=self.inflate_style,
              nonlocal_freq=self.nonlocal_freqs[i],
              nonlocal_cfg=self.nonlocal_cfg
              if i in self.nonlocal_stages
              else None,
              norm_layer=norm_layer,
              norm_kwargs=norm_kwargs,
              layer_name=layer_name,
          )
          self.inplanes = planes * self.block.expansion
          self.res_layers.add(res_layer)
  
      self.feat_dim = (
          self.block.expansion * 64 * 2 ** (len(self.stage_blocks) - 1)
      )
  
      # We use ``GlobalAvgPool3D`` here for simplicity. Otherwise the input size must be fixed.
      # You can also use ``AvgPool3D`` and specify the arguments on your own, e.g.
      # self.st_avg = nn.AvgPool3D(pool_size=(4, 7, 7), strides=1, padding=0)
      # ``AvgPool3D`` is 10% faster, but ``GlobalAvgPool3D`` makes the code cleaner.
      self.st_avg = nn.GlobalAvgPool3D()
  
      self.head = nn.HybridSequential(prefix="")
      self.head.add(nn.Dropout(rate=self.dropout_ratio))
      self.fc = nn.Dense(
          in_units=self.feat_dim,
          units=nclass,
          weight_initializer=init.Normal(sigma=self.init_std),
      )
      self.head.add(self.fc)
  
      self.init_weights(ctx)
  
imports: from mxnet import nd
  from mxnet import init
  from mxnet.context import cpu
  from mxnet.gluon.block import HybridBlock
  from mxnet.gluon import nn
  from mxnet.gluon.nn import BatchNorm
  from ..resnetv1b import resnet50_v1b, resnet101_v1b
  from .non_local import build_nonlocal_block
label_desc: Use image node_id 1 to create a new I3D_ResNetV1 object from inherited base classes: HybridBlock with example: obj = I3D_ResNetV1(nclass, depth, num_stages, pretrained, pretrained_base, feat_ext, num_segments, num_crop, spatial_strides, temporal_strides, dilations, out_indices, conv1_kernel_t, conv1_stride_t, pool1_kernel_t, pool1_stride_t, inflate_freq, inflate_stride, inflate_style, nonlocal_stages, nonlocal_freq, nonlocal_cfg, bn_eval, bn_frozen, partial_bn, frozen_stages, dropout_ratio, init_std, norm_layer, norm_kwargs, ctx)