Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #
- # based on: https://medium.com/@guymodscientist/object-detection-with-10-lines-of-code-d6cb4d86f606
- #
- from imageai.Detection import ObjectDetection
- import os
- import sys
- import time
- APP_HOME = os.path.abspath(os.path.dirname(sys.argv[0]))
- model_path = os.path.join(APP_HOME, "resnet50_coco_best_v2.0.1.h5")
- input_image = os.path.join(APP_HOME, "image.jpg")
- output_image = os.path.join(APP_HOME, "imagenew.jpg")
- start_time = time.time()
- detector = ObjectDetection()
- detector.setModelTypeAsRetinaNet()
- detector.setModelPath(model_path)
- detector.loadModel()
- detections = detector.detectObjectsFromImage(input_image=input_image, output_image_path=output_image)
- for eachObject in detections:
- print(eachObject["name"], ":", eachObject["percentage_probability"])
- end_time = time.time()
- print('running time:', end_time - start_time, 'second(s)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement