%load_ext watermark
%watermark -a "Romell D.Z." -u -d -p numpy,pandas,matplotlib,keras,imageai
The watermark extension is already loaded. To reload it, use: %reload_ext watermark Romell D.Z. last updated: 2019-02-22 numpy 1.16.1 pandas 0.23.4 matplotlib 2.2.2 keras 2.2.4 imageai n
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from IPython.display import Image,display
pathA = 'snapshot/teamA.jpg'
pathB = 'snapshot/teamB.jpg'
from imageai.Detection import ObjectDetection
import os
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( "../../../Python Samples/_TensorFlow/models/resnet50_coco_best_v2.0.1.h5")
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image= "snapshot/teamA.jpg",
output_image_path= "snapshot/objectDetectionTeamA.jpg",
minimum_percentage_probability = 80)
for eachObject in detections:
print(eachObject["name"] + " : " + str(eachObject["percentage_probability"]) )
potted plant : 91.03466868400574 person : 91.60103797912598 person : 90.57185053825378 person : 95.18238306045532 person : 97.53724932670593
display(Image(filename="snapshot/teamB.jpg"))
detections, extracted_images = detector.detectObjectsFromImage(input_image= "snapshot/teamB.jpg",
output_image_path= "snapshot/objectDetectionTeamB.jpg",
minimum_percentage_probability = 65,
extract_detected_objects=True)
display(Image(filename="snapshot/objectDetectionTeamB.jpg"))
for eachObject,image in zip(detections,extracted_images):
print(eachObject["name"] + " : " + str(eachObject["percentage_probability"]) )
display(Image(filename=image))
bottle : 69.12497878074646
person : 72.84767627716064
person : 87.89149522781372
person : 77.4427056312561
tv : 92.00461506843567
person : 69.57027912139893
person : 91.11941456794739