-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_processor.py
34 lines (25 loc) · 1.05 KB
/
image_processor.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
import os
from imageai.Detection import ObjectDetection
from imageai.Prediction import ImagePrediction
resNetModel = 'models/DenseNet-BC-121-32.h5'
resNetDetectionModel = 'models/resnet50_coco_best_v2.0.1.h5'
execution_path = os.getcwd()
model_path = os.path.join(execution_path, resNetModel)
detection_model_path = os.path.join(execution_path, resNetDetectionModel)
# Predictions
prediction = ImagePrediction()
prediction.setModelTypeAsDenseNet()
prediction.setModelPath(model_path)
prediction.loadModel()
# Detections
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(detection_model_path)
detector.loadModel()
def predict_types(img):
predictions, probabilities = prediction.predictImage(img.strip(), result_count=5)
return list(zip(predictions, probabilities))
def detect_objects(img):
return detector.detectObjectsFromImage(input_image=img.strip(),
output_image_path="images/analyzed_image.jpg",
minimum_percentage_probability=30)