Last active
February 29, 2020 22:36
-
-
Save comtom/406f7ee41d12bc4dcadd5001e2cdb7ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import cv2 | |
import numpy as np | |
from tensorflow.python.keras.preprocessing.image import load_img, img_to_array | |
from tensorflow.python.keras.models import load_model | |
from resize import resize_and_crop | |
width, height = 224, 224 | |
dimension = f'{ width }px' | |
model = 'models/model' | |
models = {} | |
for i in range(3): | |
models[i] = load_model(f'{model}{i}.model') | |
#models[i].load_weights(model_weights + i) | |
def predict(filename, model): | |
resize_and_crop(filename, size=(width, height)) | |
image = cv2.imread('./thumb.jpg') | |
image = image.astype("float") / 255.0 | |
image = image.flatten() | |
image = image.reshape((1, width, height, 3)) | |
array = models[model].predict(image)[0] | |
answer = array.argmax(axis=0) | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment