class_docstr: ResNe(x)t_SlowFast backbone.
  Args:
      depth (int): Depth of resnet, from {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.
      style (str): `pytorch` or `caffe`. If set to "pytorch", the stride-two
          layer is the 3x3 conv layer, otherwise the stride-two layer is
          the first 1x1 conv layer.
      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.
      with_cp (bool): Use checkpoint or not. Using checkpoint will save some
          memory while slowing down the training speed.
class_docstr_tok: ["ResNe","(","x",")","t_SlowFast","backbone",".","Args",":","depth","(","int",")",":","Depth","of","resnet",",","from","{","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",".","style","(","str",")",":","`","pytorch","`","or","`","caffe","`",".","If","set","to","``","pytorch","''",",","the","stride-two","layer","is","the","3x3","conv","layer",",","otherwise","the","stride-two","layer","is","the","first","1x1","conv","layer",".","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",".","with_cp","(","bool",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed","."]
code: def init_weights(self):
      if not self.pretrained_base:
          raise RuntimeError(
              "TPN 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 TPN models at this moment."
              )
  
          for name, module in self.named_modules():
              if isinstance(module, nn.Conv3d) and rhasattr(R2D, name):
                  new_weight = (
                      rgetattr(R2D, name)
                      .weight.data.unsqueeze(2)
                      .expand_as(module.weight)
                      / module.weight.data.shape[2]
                  )
                  module.weight.data.copy_(new_weight)
                  if (
                      hasattr(module, "bias")
                      and module.bias is not None
                  ):
                      new_bias = rgetattr(R2D, name).bias.data
                      module.bias.data.copy_(new_bias)
              elif isinstance(module, nn.BatchNorm3d) and rhasattr(
                  R2D, name
              ):
                  for attr in [
                      "weight",
                      "bias",
                      "running_mean",
                      "running_var",
                  ]:
                      setattr(
                          module,
                          attr,
                          getattr(rgetattr(R2D, name), attr),
                      )
          print("TPN weights inflated from pretrained C2D.")
  
imports: import numpy
  import torch
  import torch.nn
  import torch.utils.checkpoint
  import torch.nn.functional
label_desc: Use image node_id 2 for calling the TPNet obj's underlying member method code with example usage: obj.init_weights() without return types