-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
94 lines (70 loc) · 3.84 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 25 05:42:17 2015
@author: schurterb
Call a matlab function to test the predictions made by a convolutional network.
"""
import os
import ConfigParser
import argparse
from analysis import Analyzer
from load_data import LoadData
def testprediction(config_file, pred_file=None, label_file=None, out_path=None):
config = ConfigParser.ConfigParser()
config.read(config_file)
test_data = LoadData(directory = config.get('Testing Data', 'folders').split(','),
data_file_name = config.get('Testing Data', 'data_file'),
label_file_name = config.get('Testing Data', 'label_file'),
seg_file_name = config.get('Testing Data', 'seg_file'))
res = Analyzer(raw = test_data.get_data()[0],
target = test_data.get_labels()[0])
res.add_results(results_folder = config.get('General','directory'),
name = config_file.split('/')[-3],
prediction_file = config.get('Testing', 'prediction_file')+'_0',
learning_curve_file = 'learning_curve')
res.analyze(-1, pred_file=pred_file, label_file=label_file, out_path=out_path)
return res
def testall(directory, pred_file=None, label_file=None, out_path=None):
folders = os.listdir(directory)
networks = []
for folder in folders:
if os.path.isfile(directory+folder+"/network.cfg") and os.path.exists(directory+folder+"/results"):
networks.append(folder)
config_file = directory+networks[0]+"/network.cfg"
config = ConfigParser.ConfigParser()
config.read(config_file)
test_data = LoadData(directory = config.get('Testing Data', 'folders').split(','),
data_file_name = config.get('Testing Data', 'data_file'),
label_file_name = config.get('Testing Data', 'label_file'),
seg_file_name = config.get('Testing Data', 'seg_file'))
res = Analyzer(raw = test_data.get_data()[0],
target = test_data.get_labels()[0])
for net in networks:
config_file = directory+net+"/network.cfg"
config = ConfigParser.ConfigParser()
config.read(config_file)
res.add_results(results_folder = config.get('General','directory'),
name = net,
prediction_file = config.get('Testing', 'prediction_file')+'_0',
learning_curve_file = 'learning_curve')
res.analyze(-1, pred_file=pred_file, label_file=label_file, out_path=out_path)
return res
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-c", help="Path to network config file. Default is current directory.")
parser.add_argument("-n", help="Name of network folder in networks directory. Overrides -c flag.")
parser.add_argument("-all", help="Test the prediction in each folder of the provided directory. Overrides -c and -n flags.")
# parser.add_argument("--data", help="Path to prediction to test - overrides [Testing Data] section in config file.")
# parser.add_argument("--labels", help="Path to labels for testing prediction - overrides [Testing Data] section in config file.")
# parser.add_argument("--outpath", help="Path to folder where test results should be stored - overrides [Testing] section in config file.")
args = parser.parse_args()
if args.c:
config_file = args.c
else:
config_file = "network.cfg"
if args.n:
config_file = "networks/" + args.n + "/network.cfg"
if args.all:
testall(args.all)#, args.data, args.labels, args.outpath)
else:
testprediction(config_file)#, args.data, args.labels, args.outpath)