class_docstr: DenseNetHandler handler class. This handler takes an image
  and returns the name of object in that image.
class_docstr_tok: ["DenseNetHandler","handler","class",".","This","handler","takes","an","image","and","returns","the","name","of","object","in","that","image","."]
docstr: First try to load torchscript else load eager mode state_dict based model
docstr_tok: ["First","try","to","load","torchscript","else","load","eager","mode","state_dict","based","model"]
code: def initialize(self, context):
      """First try to load torchscript else load eager mode state_dict based model"""
  
      properties = context.system_properties
      self.map_location = (
          "cuda"
          if torch.cuda.is_available()
          and properties.get("gpu_id") is not None
          else "cpu"
      )
      self.device = torch.device(
          self.map_location + ":" + str(properties.get("gpu_id"))
          if torch.cuda.is_available()
          and properties.get("gpu_id") is not None
          else self.map_location
      )
      self.manifest = context.manifest
  
      model_dir = properties.get("model_dir")
      serialized_file = self.manifest["model"]["serializedFile"]
      model_pt_path = os.path.join(model_dir, serialized_file)
  
      if not os.path.isfile(model_pt_path):
          raise RuntimeError("Missing the model.pt file")
  
      # model def file
      model_file = self.manifest["model"].get("modelFile", "")
  
      if model_file:
          logger.debug("Loading eager model")
          self.model = self._load_pickled_model(
              model_dir, model_file, model_pt_path
          )
      else:
          logger.debug("Loading torchscript model")
          self.model = self._load_torchscript_model(model_pt_path)
  
      self.model.to(self.device)
      self.model.eval()
  
      logger.debug("Model file %s loaded successfully", model_pt_path)
  
      self.initialized = True
  
file_path: serve/ts/torch_handler/densenet_handler.py
imports: import inspect
  import logging
  import os
  import importlib.util
  import time
  import io
  import torch
label_desc: Use image node_id 2 for calling the DenseNetHandler obj's underlying member method code with example usage: obj.initialize(context) without return types