class_docstr: An implementation that allows for easy classification of images
  using the state of the art computer vision classification model
  trained on custom data.
  
  The class provides 4 different classification models which are ResNet50, DensesNet121, InceptionV3 and MobileNetV2.
  
  The following functions are required to be called before a classification can be made
  
  * At least of of the following and it must correspond to the model set in the setModelPath()
  [setModelTypeAsMobileNetV2(), setModelTypeAsResNet(), setModelTypeAsDenseNet, setModelTypeAsInceptionV3]
  
  * setModelPath: This is used to specify the absolute path to the trained model file.
  
  * setJsonPath: This is used to specify the absolute path to the
  json file saved during the training of the custom model.
  
  * useCPU (Optional): If you will like to force the image classification to be performed on CPU, call this function.
  
  * loadModel: Used to load the trained model weights and json data.
  
  * classifyImage(): Used for classifying an image.
class_docstr_tok: ["An","implementation","that","allows","for","easy","classification","of","images","using","the","state","of","the","art","computer","vision","classification","model","trained","on","custom","data",".","The","class","provides","4","different","classification","models","which","are","ResNet50",",","DensesNet121",",","InceptionV3","and","MobileNetV2",".","The","following","functions","are","required","to","be","called","before","a","classification","can","be","made","*","At","least","of","of","the","following","and","it","must","correspond","to","the","model","set","in","the","setModelPath","(",")","[","setModelTypeAsMobileNetV2","(",")",",","setModelTypeAsResNet","(",")",",","setModelTypeAsDenseNet",",","setModelTypeAsInceptionV3","]","*","setModelPath",":","This","is","used","to","specify","the","absolute","path","to","the","trained","model","file",".","*","setJsonPath",":","This","is","used","to","specify","the","absolute","path","to","the","json","file","saved","during","the","training","of","the","custom","model",".","*","useCPU","(","Optional",")",":","If","you","will","like","to","force","the","image","classification","to","be","performed","on","CPU",",","call","this","function",".","*","loadModel",":","Used","to","load","the","trained","model","weights","and","json","data",".","*","classifyImage","(",")",":","Used","for","classifying","an","image","."]
docstr: 'loadModel()' function is used to load the model weights into the model architecture from the file path defined
  in the setModelPath() function.
  :return:
docstr_tok: ["'loadModel","(",")","'","function","is","used","to","load","the","model","weights","into","the","model","architecture","from","the","file","path","defined","in","the","setModelPath","(",")","function",".",":","return",":"]
code: def loadModel(self) -> None:
      """
      'loadModel()' function is used to load the model weights into the model architecture from the file path defined
      in the setModelPath() function.
      :return:
      """
      if not self.__model_loaded:
          self.__load_classes()
          try:
              # change the last layer of the networks to conform to the number
              # of unique classes in the custom dataset used to train the custom
              # model
  
              if self.__model_type == "resnet50":
                  self.__model = resnet50(pretrained=False)
                  in_features = self.__model.fc.in_features
                  self.__model.fc = nn.Linear(
                      in_features, len(self.__class_names)
                  )
              elif self.__model_type == "mobilenet_v2":
                  self.__model = mobilenet_v2(pretrained=False)
                  in_features = self.__model.classifier[1].in_features
                  self.__model.classifier[1] = nn.Linear(
                      in_features, len(self.__class_names)
                  )
              elif self.__model_type == "inception_v3":
                  self.__model = inception_v3(pretrained=False)
                  in_features = self.__model.fc.in_features
                  self.__model.fc = nn.Linear(
                      in_features, len(self.__class_names)
                  )
              elif self.__model_type == "densenet121":
                  self.__model = densenet121(pretrained=False)
                  in_features = self.__model.classifier.in_features
                  self.__model.classifier = nn.Linear(
                      in_features, len(self.__class_names)
                  )
              else:
                  raise RuntimeError(
                      "Unknown model type.\nEnsure the model type is properly set."
                  )
  
              state_dict = torch.load(
                  self.__model_path, map_location=self.__device
              )
  
              if self.__model_type == "densenet121":
                  # '.'s are no longer allowed in module names, but previous densenet layers
                  # as provided by the pytorch organization has names that uses '.'s.
                  pattern = re.compile(
                      r"^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\."
                      "(?:weight|bias|running_mean|running_var))$"
                  )
                  for key in list(state_dict.keys()):
                      res = pattern.match(key)
                      if res:
                          new_key = res.group(1) + res.group(2)
                          state_dict[new_key] = state_dict[key]
                          del state_dict[key]
  
              self.__model.load_state_dict(state_dict)
              self.__model.to(self.__device).eval()
              self.__model_loaded = True
  
          except Exception as e:
              raise Exception(
                  "Weight loading failed.\nEnsure the model path is"
                  " set and the weight file is in the specified model path."
              )
  
imports: import time, warnings
  import os
  import copy
  import re
  import json
  from typing import List, Tuple, Union
  from PIL import Image
  import numpy
  import torch
  import torch.nn
  from torch.optim import lr_scheduler
  from torchvision import datasets
  from torchvision import transforms
  from torchvision.models import mobilenet_v2, inception_v3, resnet50, densenet121
  from torchvision.models.inception import InceptionOutputs
  from .data_transformation import data_transforms1, data_transforms2
  from .training_params import resnet50_train_params, densenet121_train_params, inception_v3_train_params, mobilenet_v2_train_params
  from tqdm import tqdm
  from ...backend_check.model_extension import extension_check
label_desc: Use image node_id 11 for calling the CustomImageClassification obj's underlying member method code with example usage: obj.loadModel() without return types