-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
46 lines (37 loc) · 1.21 KB
/
predict.py
File metadata and controls
46 lines (37 loc) · 1.21 KB
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
33
34
35
36
37
38
39
40
41
42
43
# import necessary packages
from sklearn import preprocessing, metrics
from sklearn.neural_network import MLPClassifier
from sklearn.svm import LinearSVC
from sklearn.externals import joblib
from dwave.system.samplers import DWaveSampler
from dwave.system.composites import EmbeddingComposite
import warnings
warnings.filterwarnings('ignore')
import glob
import numpy as np
from matplotlib.image import imread
import cv2
import sys
from qboost import QboostPlus
scaler = joblib.load('clfs/scaler.pkl')
normalizer = joblib.load('clfs/normalizer.pkl')
clf2 = joblib.load('clfs/clf2.pkl')
clf4 = joblib.load('clfs/clf4.pkl')
clf5 = joblib.load('clfs/clf5.pkl')
# This should be an image filepath
img = sys.argv[-1]
hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)
def extract_features(img):
img = cv2.resize(imread(str(img)),(64,64))
return np.squeeze(hog.compute(img))
def is_hot_dog(img, clf):
features = extract_features(img).reshape(1,-1)
features = scaler.transform(features)
features = normalizer.transform(features)
pred = clf.predict(features)
if pred:
return True
return False
qb = QboostPlus([clf2, clf4, clf5])
qb.estimator_weights = [1,1,1]
print(is_hot_dog(img, qb))