-
Notifications
You must be signed in to change notification settings - Fork 1
/
image-detect.py
58 lines (46 loc) · 1.38 KB
/
image-detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 08:51:29 2020
@author: tanmay
"""
import cv2
import argparse
from imageai.Detection import ObjectDetection
parser = argparse.ArgumentParser()
parser.add_argument(
'--load-path',
help = 'Path to Image',
type = str,
required = True
)
parser.add_argument(
'--model-name',
help = 'Model which you want',
type = str,
default = "YOLO-tiny"
)
parser.add_argument(
'--save-path',
help = 'Path to Image',
type = str,
default = "new.jpg"
)
args = parser.parse_args()
arguments = args.__dict__
detector = ObjectDetection()
if (arguments['model_name'] == 'YOLO'):
detector.setModelTypeAsYOLOv3()
detector.setModelPath("yolo.h5")
elif (arguments['model_name'] == 'Retinanet'):
detector.setModelTypeAsRetinaNet()
detector.setModelPath("resnet50_coco_best_v2.0.1.h5")
else:
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath("yolo-tiny.h5")
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image = arguments['load_path'], \
output_image_path = arguments['save_path'], \
minimum_percentage_probability = 30)
for eachObject in detections:
print(eachObject["name"] , " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] )