-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_object_prediction_from_image.py
More file actions
34 lines (23 loc) · 1.13 KB
/
basic_object_prediction_from_image.py
File metadata and controls
34 lines (23 loc) · 1.13 KB
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.Prediction import ImagePrediction
def predict_objects_densnet(filename):
prediction = ImagePrediction()
prediction.setModelTypeAsDenseNet()
prediction.setModelPath(os.path.join(os.getcwd(), "models/DenseNet-BC-121-32.h5"))
prediction.loadModel()
print("----------DenseNet--------------")
predictions, probabilities = prediction.predictImage(filename, result_count=20)
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction, " : ", eachProbability)
def predict_objects_resnet(filename):
prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(os.getcwd(), "models/resnet50_weights_tf_dim_ordering_tf_kernels.h5"))
prediction.loadModel()
print("----------ResNet--------------")
predictions, probabilities = prediction.predictImage(filename, result_count=20)
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction, " : ", eachProbability)
if __name__ == "__main__":
filename = "examples/pub.jpg"
predict_objects_resnet(filename)