-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathboss_model.py
31 lines (27 loc) · 980 Bytes
/
boss_model.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
import cv2
import keras
import numpy as np
from keras.models import load_model
from keras.preprocessing import image
from keras.utils.generic_utils import CustomObjectScope
# Load pretrained model
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
model = load_model('./model/model.h5')
IMAGE_SIZE=224
def prepare_image(img):
img_array = image.img_to_array(img)
img_array_expanded_dims = np.expand_dims(img_array, axis=0)
return keras.applications.mobilenet.preprocess_input(img_array_expanded_dims)
def predict(img):
"""
Predict face crop from frame
:param img:
:return: If boss is appear when open the code IDE
"""
try:
img = cv2.resize(img, (IMAGE_SIZE, IMAGE_SIZE), interpolation=cv2.INTER_AREA)
probs = model.predict(prepare_image(img))
is_boss = np.argmax(probs[0])
return is_boss
except:
return False