code: def get_model(
      model_weights,
      model_height,
      model_width,
      optimize_model=None,
      pose_decriptor=None,
  ):
      if optimize_model is None:
          optimize_model = not model_weights.endswith("_trt.pth")
      if optimize_model:
          weights_file_name = model_weights[:-4]  # remove .pth
  
          if pose_decriptor is None:
              # First, let's load the JSON file which describes the human pose task.
              with open(
                  "/trt_pose/tasks/human_pose/human_pose.json", "r"
              ) as f:
                  pose_decriptor = json.load(f)
  
          # Next, we'll load our model.
          num_parts = len(pose_decriptor["keypoints"])
          num_links = len(pose_decriptor["skeleton"])
  
          if "resnet18" in model_weights:
              model = (
                  trt_pose.models.resnet18_baseline_att(
                      num_parts, 2 * num_links
                  )
                  .cuda()
                  .eval()
              )
          elif "densenet121" in model_weights:
              model = (
                  trt_pose.models.densenet121_baseline_att(
                      num_parts, 2 * num_links
                  )
                  .cuda()
                  .eval()
              )
          else:
              raise ValueError(
                  "Model should be 'resnet18' or 'densenet121'"
              )
  
          # Next, let's load the model weights.
          model.load_state_dict(torch.load(model_weights))
  
          # In order to optimize with TensorRT using the python library *torch2trt* we'll also need to create some example data.
          # The dimensions of this data should match the dimensions that the network was trained with.
          data = torch.zeros((1, 3, model_height, model_width)).cuda()
  
          # Next, we'll use torch2trt.  We'll enable fp16_mode to allow optimizations to use reduced half precision.
          model_trt = torch2trt.torch2trt(
              model, [data], fp16_mode=True, max_workspace_size=1 << 25
          )
  
          # The optimized model may be saved so that we do not need to perform optimization again, we can just load the model.
          optimized_model_path = f"{weights_file_name}_trt.pth"
          torch.save(model_trt.state_dict(), optimized_model_path)
      else:
          optimized_model_path = model_weights
  
      # We could then load the optimized model using *torch2trt* as follows.
      model_trt = TRTModule()
      model_trt.load_state_dict(torch.load(optimized_model_path))
  
      return model_trt
  
file_path: norfair/demos/profiling/src/utils.py
imports: import json
  import cv2
  import numpy
  import PIL.Image
  import torch
  import torch2trt
  import torchvision.transforms
  import trt_pose.coco
  import trt_pose.models
  from torch2trt import TRTModule
  from trt_pose.parse_objects import ParseObjects
  from norfair import Detection
  from norfair.distances import create_keypoints_voting_distance, create_normalized_mean_euclidean_distance
  from norfair.filter import FilterPyKalmanFilterFactory, NoFilterFactory, OptimizedKalmanFilterFactory
label_desc: Use image node_id 4 for calling a global function with example usage: get_model(model_weights, model_height, model_width, optimize_model, pose_decriptor) and returns: model_trt