Test suite setup

This commit is contained in:
Arne van Iterson 2023-10-21 14:49:03 +02:00
parent 5b582a4afe
commit 38501bbc84
3 changed files with 36 additions and 7 deletions

Binary file not shown.

View File

@ -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

View File

@ -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: