code: def create_model(
      model_name: str = "tsm_k400_r50_seg8",
      pretrained: bool = False,
      weights_path: str = None,
      device: str = None,
  ):
      if device is None:
          device = "cuda" if torch.cuda.is_available() else "cpu"
      if model_name == "tsm_k400_r50_seg8":
          model_config = _C.MODEL.TSMK400R50
      elif model_name == "tsm_k400_r50_seg16":
          model_config = _C.MODEL.TSMK400R50S16
      elif model_name == "tsm_some_r50_seg8":
          model_config = _C.MODEL.TSMSOMER50
      elif model_name == "tsm_somev2_r50_seg16":
          model_config = _C.MODEL.TSMSOMEV2R50SEG16
      elif model_name == "tsm_flow_k400_r50_seg8":
          model_config = _C.MODEL.TSMFlowK400R50
      else:
          raise AttributeError(f"Invalid model_name {model_name}.")
      model = TSN(
          num_class=model_config.num_class,
          num_segments=model_config.num_segments,
          new_length=model_config.new_length,
          modality=model_config.input_modality,
          base_model=model_config.base_model,
          consensus_type=model_config.consensus_module,
          img_feature_dim=model_config.img_feature_dim,
          pretrain=model_config.pretrain,
          is_shift=model_config.is_shift,
          shift_div=model_config.shift_div,
          shift_place=model_config.shift_place,
          non_local=model_config.non_local,
          dropout=model_config.dropout_ratio,
      )
      if pretrained:
          checkpoint = torch.load(weights_path, map_location=device)
          checkpoint = checkpoint["state_dict"]
          base_dict = {
              ".".join(k.split(".")[1:]): v
              for k, v in list(checkpoint.items())
          }
          replace_dict = {
              "base_model.classifier.weight": "new_fc.weight",
              "base_model.classifier.bias": "new_fc.bias",
          }
          for k, v in replace_dict.items():
              if k in base_dict:
                  base_dict[v] = base_dict.pop(k)
          model.load_state_dict(base_dict)
      model.to(device)
      return model
  
imports: import torch
  from torch import nn
  from torch.nn.init import normal_, constant_
  import numpy
  import torchvision
  from towhee.models.utils.basic_ops import ConsensusModule
  from towhee.models.layers.non_local import make_non_local
  from towhee.models.tsm.mobilenet_v2 import mobilenet_v2, InvertedResidual
  from towhee.models.tsm.temporal_shift import TemporalShift, make_temporal_shift
  from towhee.models.tsm.config import _C
label_desc: Use image node_id 1 for calling a global function with example usage: create_model(model_name, pretrained, weights_path, device) and returns: model