Repository navigation
Expand file tree
/
Copy pathtest_file.py
More file actions
48 lines (36 loc) · 1.53 KB
/
Copy pathtest_file.py
File metadata and controls
48 lines (36 loc) · 1.53 KB
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
'''
Read the notes carefully
1. Note you should only replace 'somewhere' and 'YourFunction' with your own model but WITHOUT any other modifications when you submit this file
2. Run this file on validation set by '' python test.py --testfolder ../Validation_with_labels --num_class 10'', where '../Validation_with_labels' is the path of validation set, 10/107 is number of classes
'''
## import your model: replace 'somewhere' and 'YourFunction'
from Model import predict
import numpy as np
import os
import argparse
if __name__ == "__main__":
# read the test folder
parser = argparse.ArgumentParser(description='parameters setting')
parser.add_argument('--testfolder', type=str, default='/dataset/Data10/Validation_with_labels')
parser.add_argument('--num_class', type=int, default=10)
args = parser.parse_args()
testfolder = args.testfolder
print(args.testfolder)
# read true_ids
true_ids = np.load(os.path.join(testfolder, 'true_ids.npy'))
# read files
files = os.listdir(testfolder)
files.sort()
# predict the ids
predict_ids = []
time_use = []
for filename in files:
# ignore true_ids.npy
if filename == 'true_ids.npy':
continue
data = np.load(os.path.join(testfolder, filename))
predict_id = predict(data, true_ids, args.num_class)
predict_ids.append(predict_id)
# compute the test accuracy
test_accuracy = np.mean(np.array(predict_ids) == np.array(true_ids))
print('Test Accuracy: {:.2f}'.format(test_accuracy))