diff --git a/requirements.txt b/requirements.txt index f92b3d8..56caf5e 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/src/helpers/test/knn.py b/src/helpers/test/knn.py index 35f9204..970bb1e 100644 --- a/src/helpers/test/knn.py +++ b/src/helpers/test/knn.py @@ -4,6 +4,7 @@ import csv from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler, MaxAbsScaler import argparse from enum import Enum +import yaml parser = argparse.ArgumentParser(prog='KNN Train CLI') parser.add_argument('-i', '--input', help='Input CSV file', required=True) @@ -21,6 +22,8 @@ class Tree(Enum): class CVSuiteTestKNN: def __init__(self, model = None): + self.scale = [] + if model is None: self.knn = cv.ml.KNearest_create() self.trained = False @@ -69,6 +72,8 @@ class CVSuiteTestKNN: # scaler = MinMaxScaler() scaler = MaxAbsScaler() + # Perform standard scaling + self.scale.append(scaler.fit(column)) column = scaler.fit_transform(column) # Reshape it back cus scaler is dumb af diff --git a/src/suite.py b/src/suite.py index de321bd..0e5e436 100644 --- a/src/suite.py +++ b/src/suite.py @@ -1,13 +1,20 @@ #!/usr/bin/python3 + +# Path tools import pathlib import glob -import json import datetime -import os import copy + +# File IO from io import open +import os +import json + +# OpenCV import numpy as np import cv2 +from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler, MaxAbsScaler # GUI import pygubu @@ -15,7 +22,7 @@ import matplotlib.pyplot as plt # Helpers from helpers.statistics import imgStats -from helpers.logger import CVSuiteLogger, C_DBUG +from helpers.logger import CVSuiteLogger, C_DBUG, C_WARN from helpers.canvas import CVSuiteCanvas from helpers.sift import getSiftData @@ -35,6 +42,7 @@ config_json = json.load(config_file) ## UI class setup class CVSuite: def __init__(self, master=None): + # Pygubu builder self.builder = builder = pygubu.Builder() builder.add_resource_path(PROJECT_PATH) builder.add_from_file(PROJECT_UI) @@ -85,7 +93,10 @@ class CVSuite: builder.connect_callbacks(self) # Model tests - self.test_knn = CVSuiteTestKNN(config_json["models"]["knn"]) + if config_json["models"]["knn"] != "": + self.test_knn = CVSuiteTestKNN(config_json["models"]["knn"]) + else: + self.test_knn = None # Load values from config after UI has been initialised self.img_path.set(config_json["path"]) @@ -273,13 +284,26 @@ class CVSuite: self.log.add(f"Mean {label}", mean[idx]) self.log.add(f"Std {label}", std[idx]) - def runTest(self, event=None): + def runTest(self, data, event=None): output = self.builder.get_object("testdata") output.configure(state="normal") output.delete(1.0, "end") - output.insert("end", "test\n") + # Normalise data + tag = data.pop(0) + photoId = data.pop(1) + print(data) + for value in data: + print(value) + + if self.test_knn is not None: + # Do knn test + output.insert("end", "KNN Result:\n") + pass + else: + print(C_WARN, "KNN Model not configured!") + output.configure(state="disabled") def updatePath(self): @@ -422,7 +446,7 @@ class CVSuite: self.log.add("SIFT average response", siftData[6]) # Run tests - self.runTest() + self.runTest(self.log.data) # Write results to CSV file if not part_update: