-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain.py
35 lines (29 loc) · 1.35 KB
/
brain.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
# # New Version:
# # imageai.Prediction no longer exists, replaced by imageai.Classification
from imageai.Classification import ImageClassification
import os
exec_path = os.getcwd()
prediction = ImageClassification()
# SqueezeNet model also no longer exists, now the fastest is MobileNetV2
prediction.setModelTypeAsMobileNetV2()
prediction.setModelPath(os.path.join(exec_path, 'mobilenet_v2-b0353104.pth'))
prediction.loadModel()
predctions, probabilities = prediction.classifyImage(
os.path.join(exec_path, 'house.jpg'), result_count=5)
for eachPred, eachProb in zip(predctions, probabilities):
print(f'{eachPred} : {eachProb}')
# # # --------------------------------------------------------------------
# # # Old Version:
# from imageai.Prediction import ImagePrediction
# import os
# # execution_path = os.getcwd()
# execution_path = '/home/susana/anaconda3/envs/udemy_python/lib/python3.10/site-packages'
# prediction = ImagePrediction()
# prediction.setModelTypeAsSqueezeNet()
# prediction.setModelPath(os.path.join(
# execution_path, "squeezenet_weights_tf_dim_ordering_tf_kernels.h5"))
# prediction.loadModel()
# predictions, probabilities = prediction.predictImage(
# os.path.join(execution_path, "giraffe.jpg"), result_count=5)
# for eachPrediction, eachProbability in zip(predictions, probabilities):
# print(eachPrediction, " : ", eachProbability)