-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict.py
33 lines (29 loc) · 1 KB
/
predict.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
33
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC, LinearSVC
from sklearn.linear_model import SGDClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score, confusion_matrix, roc_curve, roc_auc_score
from sklearn.model_selection import train_test_split, GridSearchCV
mdataset = ['apple', 'axe', 'hat', 'butterfly', 'fan']
### store the classifier
import pickle
clf = pickle.load(open('clf_rf.pickle', 'r'))
import test
#path = "/path/to/image";
#x = test.imageprepare(path);
#TODO:try catch for exceptions
import sys
if len(sys.argv) == 2:
#path of the uploaded image as given by php
path = sys.argv[1]
#convert to array of 784
x = test.imageprepare(path)
#predict the value and find the name of object
prediction = int ( clf.predict( [x] )[0] )
print(mdataset[prediction])
else:
print("Failure")