[2]
%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

5. Objects Detection & Extraction

[2]
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from IPython.display import Image,display
[3]
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()
[10]
detections = detector.detectObjectsFromImage(input_image= "snapshot/teamA.jpg",
                                            output_image_path= "snapshot/objectDetectionTeamA.jpg",
                                             minimum_percentage_probability = 80)
[11]
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
[12]
display(Image(filename="snapshot/teamB.jpg"))
[13]
detections, extracted_images = detector.detectObjectsFromImage(input_image= "snapshot/teamB.jpg",
                                                               output_image_path= "snapshot/objectDetectionTeamB.jpg",
                                                               minimum_percentage_probability = 65,
                                                               extract_detected_objects=True)
[14]
display(Image(filename="snapshot/objectDetectionTeamB.jpg"))