class_docstr: This is the image classification class in the ImageAI library. It provides support for 4 different models which are:
  ResNet, MobileNetV2, DenseNet and Inception V3. After instantiating this class, you can set it's properties and
  make image classification using it's pre-defined functions.
  
  The following functions are required to be called before a classification can be made
  * setModelPath()
  * At least of of the following and it must correspond to the model set in the setModelPath()
  [setModelTypeAsMobileNetv2(), setModelTypeAsResNet(), setModelTypeAsDenseNet, setModelTypeAsInceptionV3]
  * loadModel() [This must be called once only before making a classification]
  
  Once the above functions have been called, you can call the classifyImage() function of the classification instance
  object at anytime to classify an image.
class_docstr_tok: ["This","is","the","image","classification","class","in","the","ImageAI","library",".","It","provides","support","for","4","different","models","which","are",":","ResNet",",","MobileNetV2",",","DenseNet","and","Inception","V3",".","After","instantiating","this","class",",","you","can","set","it","'s","properties","and","make","image","classification","using","it","'s","pre-defined","functions",".","The","following","functions","are","required","to","be","called","before","a","classification","can","be","made","*","setModelPath","(",")","*","At","least","of","of","the","following","and","it","must","correspond","to","the","model","set","in","the","setModelPath","(",")","[","setModelTypeAsMobileNetv2","(",")",",","setModelTypeAsResNet","(",")",",","setModelTypeAsDenseNet",",","setModelTypeAsInceptionV3","]","*","loadModel","(",")","[","This","must","be","called","once","only","before","making","a","classification","]","Once","the","above","functions","have","been","called",",","you","can","call","the","classifyImage","(",")","function","of","the","classification","instance","object","at","anytime","to","classify","an","image","."]
docstr: 'classifyImage()' function is used to classify a given image by receiving the following arguments:
      * input_type (optional) , the type of input to be parsed. Acceptable values are "file", "array" and "stream"
      * image_input , file path/numpy array/image file stream of the image.
      * result_count (optional) , the number of classifications to be sent which must be whole numbers between
          1 and 1000. The default is 5.
  
  This function returns 2 arrays namely 'classification_results' and 'classification_probabilities'. The 'classification_results'
  contains possible objects classes arranged in descending of their percentage probabilities. The 'classification_probabilities'
  contains the percentage probability of each object class. The position of each object class in the 'classification_results'
  array corresponds with the positions of the percentage probability in the 'classification_probabilities' array.
  
  
  :param input_type:
  :param image_input:
  :param result_count:
  :return classification_results, classification_probabilities:
docstr_tok: ["'classifyImage","(",")","'","function","is","used","to","classify","a","given","image","by","receiving","the","following","arguments",":","*","input_type","(","optional",")",",","the","type","of","input","to","be","parsed",".","Acceptable","values","are","``","file","''",",","``","array","''","and","``","stream","''","*","image_input",",","file","path\/numpy","array\/image","file","stream","of","the","image",".","*","result_count","(","optional",")",",","the","number","of","classifications","to","be","sent","which","must","be","whole","numbers","between","1","and","1000",".","The","default","is","5",".","This","function","returns","2","arrays","namely","'classification_results","'","and","'classification_probabilities","'",".","The","'classification_results'","contains","possible","objects","classes","arranged","in","descending","of","their","percentage","probabilities",".","The","'classification_probabilities'","contains","the","percentage","probability","of","each","object","class",".","The","position","of","each","object","class","in","the","'classification_results'","array","corresponds","with","the","positions","of","the","percentage","probability","in","the","'classification_probabilities","'","array",".",":","param","input_type",":",":","param","image_input",":",":","param","result_count",":",":","return","classification_results",",","classification_probabilities",":"]
code: def classifyImage(
      self, image_input, result_count=5, input_type="file"
  ):
      """
      'classifyImage()' function is used to classify a given image by receiving the following arguments:
          * input_type (optional) , the type of input to be parsed. Acceptable values are "file", "array" and "stream"
          * image_input , file path/numpy array/image file stream of the image.
          * result_count (optional) , the number of classifications to be sent which must be whole numbers between
              1 and 1000. The default is 5.
  
      This function returns 2 arrays namely 'classification_results' and 'classification_probabilities'. The 'classification_results'
      contains possible objects classes arranged in descending of their percentage probabilities. The 'classification_probabilities'
      contains the percentage probability of each object class. The position of each object class in the 'classification_results'
      array corresponds with the positions of the percentage probability in the 'classification_probabilities' array.
  
  
      :param input_type:
      :param image_input:
      :param result_count:
      :return classification_results, classification_probabilities:
      """
      classification_results = []
      classification_probabilities = []
      if self.__modelLoaded == False:
          raise ValueError(
              "You must call the loadModel() function before making classification."
          )
  
      else:
          if input_type == "file":
              try:
                  image_to_predict = (
                      tf.keras.preprocessing.image.load_img(
                          image_input,
                          target_size=(
                              self.__input_image_size,
                              self.__input_image_size,
                          ),
                      )
                  )
                  image_to_predict = (
                      tf.keras.preprocessing.image.img_to_array(
                          image_to_predict, data_format="channels_last"
                      )
                  )
                  image_to_predict = np.expand_dims(
                      image_to_predict, axis=0
                  )
              except:
                  raise ValueError(
                      "You have set a path to an invalid image file."
                  )
          elif input_type == "array":
              try:
                  image_input = Image.fromarray(np.uint8(image_input))
                  image_input = image_input.resize(
                      (self.__input_image_size, self.__input_image_size)
                  )
                  image_input = np.expand_dims(image_input, axis=0)
                  image_to_predict = image_input.copy()
                  image_to_predict = np.asarray(
                      image_to_predict, dtype=np.float64
                  )
              except:
                  raise ValueError(
                      "You have parsed in a wrong numpy array for the image"
                  )
          elif input_type == "stream":
              try:
                  image_input = Image.open(image_input)
                  image_input = image_input.resize(
                      (self.__input_image_size, self.__input_image_size)
                  )
                  image_input = np.expand_dims(image_input, axis=0)
                  image_to_predict = image_input.copy()
                  image_to_predict = np.asarray(
                      image_to_predict, dtype=np.float64
                  )
  
              except:
                  raise ValueError(
                      "You have parsed in a wrong stream for the image"
                  )
  
          if self.__modelType == "mobilenetv2":
              image_to_predict = (
                  tf.keras.applications.mobilenet_v2.preprocess_input(
                      image_to_predict
                  )
              )
          elif self.__modelType == "densenet121":
              image_to_predict = (
                  tf.keras.applications.densenet.preprocess_input(
                      image_to_predict
                  )
              )
          elif self.__modelType == "inceptionv3":
              image_to_predict = (
                  tf.keras.applications.inception_v3.preprocess_input(
                      image_to_predict
                  )
              )
  
          try:
              model = self.__model_collection[0]
              prediction = model.predict(image_to_predict, steps=1)
  
              if self.__modelType == "mobilenetv2":
                  predictiondata = tf.keras.applications.mobilenet_v2.decode_predictions(
                      prediction, top=int(result_count)
                  )
              elif self.__modelType == "resnet50":
                  predictiondata = (
                      tf.keras.applications.resnet50.decode_predictions(
                          prediction, top=int(result_count)
                      )
                  )
              elif self.__modelType == "inceptionv3":
                  predictiondata = tf.keras.applications.inception_v3.decode_predictions(
                      prediction, top=int(result_count)
                  )
              elif self.__modelType == "densenet121":
                  predictiondata = (
                      tf.keras.applications.densenet.decode_predictions(
                          prediction, top=int(result_count)
                      )
                  )
  
              for results in predictiondata:
                  for result in results:
                      classification_results.append(str(result[1]))
                      classification_probabilities.append(
                          result[2] * 100
                      )
          except:
              raise ValueError("An error occured! Try again.")
  
          return classification_results, classification_probabilities
  
file_path: ImageAI/imageai_tf_deprecated/Classification/__init__.py
imports: import tensorflow
  from PIL import Image
  import numpy
  from matplotlib.cbook import deprecated
label_desc: Use image node_id 11 for calling the ImageClassification obj's underlying member method code with example usage: obj.classifyImage(image_input, result_count, input_type) and returns: classification_results,  classification_probabilities