title: Multiple object detection using a custom model in Python and imageai
body: <p>I have trained my own model with my own dataset of images for object recognition in an image, but it doesn't seem to recognize all the objects. I only have 2 objects (images of different ways a person types a specific letter of the alphabet). For example the letter 'a' and the letter 'o' as seen below. </p>
  
  <p><a href="https://i.stack.imgur.com/KIUO1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KIUO1.png" alt="The letter &#39;a&#39;"></a>  <a href="https://i.stack.imgur.com/JPEeF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JPEeF.png" alt="The letter &#39;o&#39;"></a></p>
  
  <p>When I run the test code on a sample of handwritten text, to a certain extent, it does say what percentage accuracy it has, but no bounding boxes. This is the image of hand written text:</p>
  
  <p><a href="https://i.stack.imgur.com/QwrZa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QwrZa.jpg" alt="Hand written text"></a></p>
  
  <p>This is the output I am getting:</p>
  
  <p><a href="https://i.stack.imgur.com/k1yNm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k1yNm.png" alt="Output I am getting"></a></p>
  
  <p><strong>I am using imageai to train the custom model. I am wondering if it is possible to use this trained model to run multiple object detection on the hand written image and perhaps show the bounding boxes?</strong></p>
  
  <p>Here is how my working directory looks like, in case it provides additional help:</p>
  
  <p><a href="https://i.stack.imgur.com/iEkxN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iEkxN.png" alt="Working directory"></a></p>
  
  <p>And here is my code for <strong>training the model (custom_detector.py):</strong></p>
  
  <pre><code>from imageai.Prediction.Custom import ModelTraining
  
  # Instanciating the model
  model_trainer = ModelTraining()
  model_trainer.setModelTypeAsResNet()
  # Setting our dataset directyory
  model_trainer.setDataDirectory("characters")
  # training the model
  model_trainer.trainModel(num_objects=2, num_experiments=100, enhance_data=True, batch_size=10)
  </code></pre>
  
  <p>This is my code for testing the trained model (<strong>test.py</strong>):</p>
  
  <pre><code>from imageai.Prediction.Custom import CustomImagePrediction
  import os
  
  # get the working directory
  execution_path = os.getcwd()
  print(execution_path)
  # instanciate prediction
  prediction = CustomImagePrediction()
  prediction.setModelTypeAsResNet()
  
  # Set model path
  prediction.setModelPath(os.path.join(execution_path, "characters", "models", "myModel.h5"))
  
  # Set JSON path
  # This is how the JSON file looks like:
  #{
  #   "0" : "A",
  #   "1" : "O"
  #}
  prediction.setJsonPath(os.path.join(execution_path, "characters", "json", "model_class.json"))
  
  # Initialize the number of objects you have retrained
  prediction.loadModel(num_objects=2)
  
  # run prediction
  predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "HandTextTest.jpg"), result_count=2)
  
  # Print each prediction
  for eachPrediction, eachProbability in zip(predictions, probabilities):
      print(eachPrediction, " : ", eachProbability)
  </code></pre>
  
  <p>Any help or advice will be highly appreicated.</p>