SHARE
TWEET

Python - imageai - ObjectDetection

furas Jun 16th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top