-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpredict_gesture.py
32 lines (26 loc) · 968 Bytes
/
predict_gesture.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
from keras.models import model_from_json
import cv2
import numpy as np
def preprocess(img):
img = cv2.resize(img, (64, 64), interpolation=cv2.INTER_NEAREST).astype(np.float32)
# print(img.shape)
return img
class GestureClassifier:
def __init__(self):
self.model = None
def load_model(self):
json_file = open('training/model.json', 'r')
loaded_model = json_file.read()
json_file.close()
self.model = model_from_json(loaded_model)
self.model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
self.model.load_weights('training/hand_detection_weights.h5')
print("completed loading model")
def predict(self, img):
# print(img.shape)
img1 = img.copy()
img1 = preprocess(img1)
k = self.model.predict(np.array([img1]))
score = max(k[0])
res = list(k[0]).index(score)
return chr(65 + res), score