Skip to content

Instantly share code, notes, and snippets.

@comtom
Last active February 29, 2020 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comtom/406f7ee41d12bc4dcadd5001e2cdb7ac to your computer and use it in GitHub Desktop.
Save comtom/406f7ee41d12bc4dcadd5001e2cdb7ac to your computer and use it in GitHub Desktop.
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