55 lines
1.6 KiB
Python

import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.feature import hog
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn import svm
from sklearn import tree
import pickle
from implement import train_and_save_model, save_data, get_data, load_data, load_model
print("Test")
img_data_path = "Data\\test_img_data.npy"
marks_data_path = "Data\\test_marks.npy"
train_baza_path = "Baza\\Pet100"
print("Loading data")
if False:
img_data, marks = get_data(train_baza_path)
save_data(img_data, marks, img_data_path, marks_data_path)
else:
img_data, marks = load_data(img_data_path, marks_data_path)
print("Loding model")
knn, svm, dt = load_model()
print("Calculating predictions")
knn_pred = knn.predict(img_data)
svm_pred = svm.predict(img_data)
dt_pred = dt.predict(img_data)
predictions = []
for i in range(len(knn_pred)):
if knn_pred[i] == svm_pred[i] == dt_pred[i]:
predictions.append(knn_pred[i])
elif knn_pred[i] == svm_pred[i]:
predictions.append(knn_pred[i])
elif knn_pred[i] == dt_pred[i]:
predictions.append(knn_pred[i])
elif svm_pred[i] == dt_pred[i]:
predictions.append(svm_pred[i])
predictions = np.array(predictions)
print("KNN: ", accuracy_score(marks, knn_pred))
print("SVM: ", accuracy_score(marks, svm_pred))
print("DT: ", accuracy_score(marks, dt_pred))
print("Accuracy: ", accuracy_score(marks, predictions))
print("End")