Diff of /test.py [000000] .. [40f229]

Switch to unified view

a b/test.py
1
from datetime import datetime
2
import numpy as np
3
import argparse
4
5
from model.initialization import initialization
6
from model.utils import evaluation
7
from config import conf
8
9
10
def boolean_string(s):
11
    if s.upper() not in {'FALSE', 'TRUE'}:
12
        raise ValueError('Not a valid boolean string')
13
    return s.upper() == 'TRUE'
14
15
16
parser = argparse.ArgumentParser(description='Test')
17
parser.add_argument('--iter', default='80000', type=int,
18
                    help='iter: iteration of the checkpoint to load. Default: 80000')
19
parser.add_argument('--batch_size', default='1', type=int,
20
                    help='batch_size: batch size for parallel test. Default: 1')
21
parser.add_argument('--cache', default=False, type=boolean_string,
22
                    help='cache: if set as TRUE all the test data will be loaded at once'
23
                         ' before the transforming start. Default: FALSE')
24
opt = parser.parse_args()
25
26
27
# Exclude identical-view cases
28
def de_diag(acc, each_angle=False):
29
    result = np.sum(acc - np.diag(np.diag(acc)), 1) / 10.0
30
    if not each_angle:
31
        result = np.mean(result)
32
    return result
33
34
35
m = initialization(conf, test=opt.cache)[0]
36
37
# load model checkpoint of iteration opt.iter
38
print('Loading the model of iteration %d...' % opt.iter)
39
m.load(opt.iter)
40
print('Transforming...')
41
time = datetime.now()
42
test = m.transform('test', opt.batch_size)
43
print('Evaluating...')
44
acc = evaluation(test, conf['data'])
45
print('Evaluation complete. Cost:', datetime.now() - time)
46
47
# Print rank-1 accuracy of the best model
48
# e.g.
49
# ===Rank-1 (Include identical-view cases)===
50
# NM: 95.405,     BG: 88.284,     CL: 72.041
51
for i in range(1):
52
    print('===Rank-%d (Include identical-view cases)===' % (i + 1))
53
    print('NM: %.3f,\tBG: %.3f,\tCL: %.3f' % (
54
        np.mean(acc[0, :, :, i]),
55
        np.mean(acc[1, :, :, i]),
56
        np.mean(acc[2, :, :, i])))
57
58
# Print rank-1 accuracy of the best model,excluding identical-view cases
59
# e.g.
60
# ===Rank-1 (Exclude identical-view cases)===
61
# NM: 94.964,     BG: 87.239,     CL: 70.355
62
for i in range(1):
63
    print('===Rank-%d (Exclude identical-view cases)===' % (i + 1))
64
    print('NM: %.3f,\tBG: %.3f,\tCL: %.3f' % (
65
        de_diag(acc[0, :, :, i]),
66
        de_diag(acc[1, :, :, i]),
67
        de_diag(acc[2, :, :, i])))
68
69
# Print rank-1 accuracy of the best model (Each Angle)
70
# e.g.
71
# ===Rank-1 of each angle (Exclude identical-view cases)===
72
# NM: [90.80 97.90 99.40 96.90 93.60 91.70 95.00 97.80 98.90 96.80 85.80]
73
# BG: [83.80 91.20 91.80 88.79 83.30 81.00 84.10 90.00 92.20 94.45 79.00]
74
# CL: [61.40 75.40 80.70 77.30 72.10 70.10 71.50 73.50 73.50 68.40 50.00]
75
np.set_printoptions(precision=2, floatmode='fixed')
76
for i in range(1):
77
    print('===Rank-%d of each angle (Exclude identical-view cases)===' % (i + 1))
78
    print('NM:', de_diag(acc[0, :, :, i], True))
79
    print('BG:', de_diag(acc[1, :, :, i], True))
80
    print('CL:', de_diag(acc[2, :, :, i], True))