Test suite setup
This commit is contained in:
parent
5b582a4afe
commit
38501bbc84
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -4,6 +4,7 @@ import csv
|
|||||||
from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler, MaxAbsScaler
|
from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler, MaxAbsScaler
|
||||||
import argparse
|
import argparse
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
import yaml
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog='KNN Train CLI')
|
parser = argparse.ArgumentParser(prog='KNN Train CLI')
|
||||||
parser.add_argument('-i', '--input', help='Input CSV file', required=True)
|
parser.add_argument('-i', '--input', help='Input CSV file', required=True)
|
||||||
@ -21,6 +22,8 @@ class Tree(Enum):
|
|||||||
|
|
||||||
class CVSuiteTestKNN:
|
class CVSuiteTestKNN:
|
||||||
def __init__(self, model = None):
|
def __init__(self, model = None):
|
||||||
|
self.scale = []
|
||||||
|
|
||||||
if model is None:
|
if model is None:
|
||||||
self.knn = cv.ml.KNearest_create()
|
self.knn = cv.ml.KNearest_create()
|
||||||
self.trained = False
|
self.trained = False
|
||||||
@ -69,6 +72,8 @@ class CVSuiteTestKNN:
|
|||||||
# scaler = MinMaxScaler()
|
# scaler = MinMaxScaler()
|
||||||
scaler = MaxAbsScaler()
|
scaler = MaxAbsScaler()
|
||||||
|
|
||||||
|
# Perform standard scaling
|
||||||
|
self.scale.append(scaler.fit(column))
|
||||||
column = scaler.fit_transform(column)
|
column = scaler.fit_transform(column)
|
||||||
|
|
||||||
# Reshape it back cus scaler is dumb af
|
# Reshape it back cus scaler is dumb af
|
||||||
|
38
src/suite.py
38
src/suite.py
@ -1,13 +1,20 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
# Path tools
|
||||||
import pathlib
|
import pathlib
|
||||||
import glob
|
import glob
|
||||||
import json
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
# File IO
|
||||||
from io import open
|
from io import open
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
|
from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler, MaxAbsScaler
|
||||||
|
|
||||||
# GUI
|
# GUI
|
||||||
import pygubu
|
import pygubu
|
||||||
@ -15,7 +22,7 @@ import matplotlib.pyplot as plt
|
|||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
from helpers.statistics import imgStats
|
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.canvas import CVSuiteCanvas
|
||||||
from helpers.sift import getSiftData
|
from helpers.sift import getSiftData
|
||||||
|
|
||||||
@ -35,6 +42,7 @@ config_json = json.load(config_file)
|
|||||||
## UI class setup
|
## UI class setup
|
||||||
class CVSuite:
|
class CVSuite:
|
||||||
def __init__(self, master=None):
|
def __init__(self, master=None):
|
||||||
|
# Pygubu builder
|
||||||
self.builder = builder = pygubu.Builder()
|
self.builder = builder = pygubu.Builder()
|
||||||
builder.add_resource_path(PROJECT_PATH)
|
builder.add_resource_path(PROJECT_PATH)
|
||||||
builder.add_from_file(PROJECT_UI)
|
builder.add_from_file(PROJECT_UI)
|
||||||
@ -85,7 +93,10 @@ class CVSuite:
|
|||||||
builder.connect_callbacks(self)
|
builder.connect_callbacks(self)
|
||||||
|
|
||||||
# Model tests
|
# 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
|
# Load values from config after UI has been initialised
|
||||||
self.img_path.set(config_json["path"])
|
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"Mean {label}", mean[idx])
|
||||||
self.log.add(f"Std {label}", std[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 = self.builder.get_object("testdata")
|
||||||
output.configure(state="normal")
|
output.configure(state="normal")
|
||||||
output.delete(1.0, "end")
|
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")
|
output.configure(state="disabled")
|
||||||
|
|
||||||
def updatePath(self):
|
def updatePath(self):
|
||||||
@ -422,7 +446,7 @@ class CVSuite:
|
|||||||
self.log.add("SIFT average response", siftData[6])
|
self.log.add("SIFT average response", siftData[6])
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
self.runTest()
|
self.runTest(self.log.data)
|
||||||
|
|
||||||
# Write results to CSV file
|
# Write results to CSV file
|
||||||
if not part_update:
|
if not part_update:
|
||||||
|
Loading…
Reference in New Issue
Block a user