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.
  Args:
      depth (int): Depth of ResNet, from {18, 34, 50, 101, 152}.
      num_stages (int): ResNet stages, normally 4.
      strides (Sequence[int]): Strides of the first block of each stage.
      dilations (Sequence[int]): Dilation of each stage.
      out_indices (Sequence[int]): Output from which stages.
      frozen_stages (int): Stages to be frozen (all param fixed). -1 means
          not freezing any parameters.
      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.
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",".","Args",":","depth","(","int",")",":","Depth","of","ResNet",",","from","{","18",",","34",",","50",",","101",",","152","}",".","num_stages","(","int",")",":","ResNet","stages",",","normally","4.","strides","(","Sequence","[","int","]",")",":","Strides","of","the","first","block","of","each","stage",".","dilations","(","Sequence","[","int","]",")",":","Dilation","of","each","stage",".","out_indices","(","Sequence","[","int","]",")",":","Output","from","which","stages",".","frozen_stages","(","int",")",":","Stages","to","be","frozen","(","all","param","fixed",")",".","-1","means","not","freezing","any","parameters",".","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","."]
docstr: Inflate I3D network with its 2D ImageNet pretrained weights.
docstr_tok: ["Inflate","I3D","network","with","its","2D","ImageNet","pretrained","weights","."]
code: def inflate_weights(self):
      """Inflate I3D network with its 2D ImageNet pretrained weights."""
  
      if not self.pretrained_base:
          raise RuntimeError(
              "I3D models need to be inflated. Please set PRETRAINED_BASE to True in config."
          )
  
      if self.pretrained_base and not self.pretrained:
          import torchvision
  
          if self.depth == 50:
              R2D = torchvision.models.resnet50(
                  pretrained=True, progress=True
              )
          elif self.depth == 101:
              R2D = torchvision.models.resnet101(
                  pretrained=True, progress=True
              )
          else:
              raise RuntimeError(
                  "We only support ResNet50 and ResNet101 for I3D models at this moment."
              )
  
          # copy conv1
          conv1 = self.first_stage._modules["0"]
          conv1_bn = self.first_stage._modules["1"]
  
          conv1.weight.data.copy_(
              torch.unsqueeze(R2D.conv1.weight.data, dim=2).repeat(
                  1, 1, 5, 1, 1
              )
          )
          conv1_bn.weight.data.copy_(R2D.bn1.weight.data)
          conv1_bn.bias.data.copy_(R2D.bn1.bias.data)
          conv1_bn.running_mean.data.copy_(R2D.bn1.running_mean.data)
          conv1_bn.running_var.data.copy_(R2D.bn1.running_var.data)
  
          res2 = self.res_layers._modules["0"]
          res3 = self.res_layers._modules["1"]
          res4 = self.res_layers._modules["2"]
          res5 = self.res_layers._modules["3"]
  
          stages = [res2, res3, res4, res5]
  
          R2Dlayers = [R2D.layer1, R2D.layer2, R2D.layer3, R2D.layer4]
  
          for s, _ in enumerate(stages):
              res = stages[s]._modules
              count = 0
  
              for k, block in res.items():
                  if block.conv1.weight.data.shape[2] > 1:
                      block.conv1.weight.data.copy_(
                          torch.unsqueeze(
                              R2Dlayers[s]
                              ._modules[str(k)]
                              .conv1.weight.data,
                              dim=2,
                          ).repeat(1, 1, 3, 1, 1)
                      )
                  else:
                      block.conv1.weight.data.copy_(
                          torch.unsqueeze(
                              R2Dlayers[s]
                              ._modules[str(k)]
                              .conv1.weight.data,
                              dim=2,
                          )
                      )
                  block.conv2.weight.data.copy_(
                      torch.unsqueeze(
                          R2Dlayers[s]
                          ._modules[str(k)]
                          .conv2.weight.data,
                          dim=2,
                      )
                  )
                  block.conv3.weight.data.copy_(
                      torch.unsqueeze(
                          R2Dlayers[s]
                          ._modules[str(k)]
                          .conv3.weight.data,
                          dim=2,
                      )
                  )
  
                  block.bn1.weight.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn1.weight.data
                  )
                  block.bn1.bias.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn1.bias.data
                  )
                  block.bn1.running_mean.data.copy_(
                      R2Dlayers[s]
                      ._modules[str(k)]
                      .bn1.running_mean.data
                  )
                  block.bn1.running_var.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn1.running_var.data
                  )
  
                  block.bn2.weight.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn2.weight.data
                  )
                  block.bn2.bias.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn2.bias.data
                  )
                  block.bn2.running_mean.data.copy_(
                      R2Dlayers[s]
                      ._modules[str(k)]
                      .bn2.running_mean.data
                  )
                  block.bn2.running_var.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn2.running_var.data
                  )
  
                  block.bn3.weight.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn3.weight.data
                  )
                  block.bn3.bias.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn3.bias.data
                  )
                  block.bn3.running_mean.data.copy_(
                      R2Dlayers[s]
                      ._modules[str(k)]
                      .bn3.running_mean.data
                  )
                  block.bn3.running_var.data.copy_(
                      R2Dlayers[s]._modules[str(k)].bn3.running_var.data
                  )
  
                  if block.downsample is not None:
                      down_conv = block.downsample._modules["0"]
                      down_bn = block.downsample._modules["1"]
  
                      down_conv.weight.data.copy_(
                          torch.unsqueeze(
                              R2Dlayers[s]
                              ._modules[str(k)]
                              .downsample._modules["0"]
                              .weight.data,
                              dim=2,
                          )
                      )
                      down_bn.weight.data.copy_(
                          R2Dlayers[s]
                          ._modules[str(k)]
                          .downsample._modules["1"]
                          .weight.data
                      )
                      down_bn.bias.data.copy_(
                          R2Dlayers[s]
                          ._modules[str(k)]
                          .downsample._modules["1"]
                          .bias.data
                      )
                      down_bn.running_mean.data.copy_(
                          R2Dlayers[s]
                          ._modules[str(k)]
                          .downsample._modules["1"]
                          .running_mean.data
                      )
                      down_bn.running_var.data.copy_(
                          R2Dlayers[s]
                          ._modules[str(k)]
                          .downsample._modules["1"]
                          .running_var.data
                      )
                  count += 1
          print("I3D weights inflated from pretrained C2D.")
  
imports: import torch
  import torch.nn
  from torch.nn import BatchNorm3d
  from .non_local import build_nonlocal_block
label_desc: Use image node_id 2 for calling the I3D_ResNetV1 obj's underlying member method code with example usage: obj.inflate_weights() without return types