analysis on all possible files in a provided directory, writes to JSON
This commit is contained in:
12
predict.py
12
predict.py
@@ -3,8 +3,12 @@ from keras.utils import load_img, img_to_array
|
||||
from keras.applications.vgg16 import preprocess_input, decode_predictions
|
||||
|
||||
def predict(model, path):
|
||||
# only allow valid file types
|
||||
if not (".jpg" in path or ".jpeg" in path):
|
||||
return None
|
||||
|
||||
# receive image path as CLI argument
|
||||
img = load_img(path ,color_mode='rgb', target_size=(224, 224))
|
||||
img = load_img(path, color_mode='rgb', target_size=(224, 224))
|
||||
|
||||
# loaded image to np array for model to read
|
||||
x = img_to_array(img)
|
||||
@@ -15,5 +19,11 @@ def predict(model, path):
|
||||
x = preprocess_input(x)
|
||||
features = model.predict(x)
|
||||
p = decode_predictions(features)
|
||||
|
||||
for predict in p:
|
||||
i = 0
|
||||
while i < len(predict):
|
||||
predict[i] = (predict[i][0], predict[i][1], str(predict[i][2]))
|
||||
i = i + 1
|
||||
|
||||
return p
|
||||
|
||||
Reference in New Issue
Block a user