-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testing.py
41 lines (38 loc) · 1.51 KB
/
Testing.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
34
35
36
37
38
39
40
import cv2;
import numpy as np;
import os;
import Classification;
def setUpTesting(SamplesSize, featurestype, modeltype):
dirtocheck = "./trainingdata/"+featurestype;
responsespath = "responses";
samplespath = "samples";
responses = [];
samples = [];
for root, _, files in os.walk(dirtocheck + responsespath):
for f in files:
fullpath = os.path.join(root, f)
# print f
newResponses = np.loadtxt(fullpath, np.float32)
newResponses = newResponses.reshape((newResponses.size,1));
responses = np.append(responses, [newResponses]);
for root, _, files in os.walk(dirtocheck + samplespath):
for f in files:
fullpath = os.path.join(root, f)
# print f
newSamples = np.loadtxt(fullpath, np.float32)
#print newSamples
samples = np.append(samples, [newSamples]);
#print samples
ninputs = len(samples)/len(responses);
samples = np.array(samples.reshape(np.size(responses),np.size(samples)/np.size(responses)), np.float32);
responses = np.array(responses, np.float32);
# print samples
# print responses
noutputs = len(set(responses));
# print ninputs
# print noutputs
model = Classification.createModel(modeltype, ninputs, noutputs);
responses_order = list(set(responses));
responses_order.sort();
Classification.trainModel(modeltype, model, responses, samples, responses_order);
return [responses, samples, model, responses_order]