Advertisement
furas

Python - imageai - ObjectDetection

Jun 16th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. #
  4. # based on: https://medium.com/@guymodscientist/object-detection-with-10-lines-of-code-d6cb4d86f606
  5. #
  6.  
  7. from imageai.Detection import ObjectDetection
  8. import os
  9. import sys
  10. import time
  11.  
  12. APP_HOME = os.path.abspath(os.path.dirname(sys.argv[0]))
  13.  
  14. model_path = os.path.join(APP_HOME, "resnet50_coco_best_v2.0.1.h5")
  15. input_image = os.path.join(APP_HOME, "image.jpg")
  16. output_image = os.path.join(APP_HOME, "imagenew.jpg")
  17.  
  18. start_time = time.time()
  19.  
  20. detector = ObjectDetection()
  21. detector.setModelTypeAsRetinaNet()
  22. detector.setModelPath(model_path)
  23. detector.loadModel()
  24. detections = detector.detectObjectsFromImage(input_image=input_image, output_image_path=output_image)
  25.  
  26. for eachObject in detections:
  27.     print(eachObject["name"], ":", eachObject["percentage_probability"])
  28.  
  29. end_time = time.time()
  30.  
  31. print('running time:', end_time - start_time, 'second(s)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement