forked from michaelbrownid/tfccs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestLR_mult.py
executable file
·93 lines (72 loc) · 2.87 KB
/
testLR_mult.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
#!/usr/bin/env python
from __future__ import print_function
import argparse
import time
import os
import sys
import numpy as np
import tensorflow as tf
import tensorflow.keras as KK
#from .model import Model
from . import data
import math
import importlib
################################
def test(args):
data_loader = data.data( args.batch_size, sys.argv[2],
inputdatName=args.inputdatName,
outputdatName=args.outputdatName)
if True:
# load the model based on name and access as Model: from .model import args.model
myimport = importlib.import_module("tfccs.%s" % args.model)
Model = myimport.Model
model = Model(args)
# make it appear as though there is only one gpu and use it
os.environ["CUDA_VISIBLE_DEVICES"]=args.CUDA_VISIBLE_DEVICES
num=0
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
# restore model
model.model = KK.models.load_model(args.modelsave)
################################
numerr = 0
total = 0
for b in range(data_loader.num_batches):
start = time.time()
x, y = data_loader.next_batch()
predictions = model.model.predict(x)
print("predictions.shape",predictions.shape)
print("y.shape",y.shape)
print("x.shape",x.shape)
#### print out all predictions
qvvec = np.array([5.0, 15.0, 25.0, 35.0, 45.0, 55.0, 65.0 ,75.0],dtype=np.float32)
if True:
#fp = open("test.LR.preds.txt","w")
for ii in range(predictions.shape[0]):
mytruth = y[ii]
estimate = predictions[ii,:]
myx = x[ii]
truemax = np.argmax(mytruth)
estmax = np.argmax(estimate)
estmean = int(np.sum(qvvec*estimate/10))
if total<8:
print(ii,"|",mytruth,estimate,estmean)
if truemax!=estmax:
#if truemax!=estmean:
numerr+=1
#print("err %d true est prob" % (ii), truemax,estmax,estimate[estmax])
total+=1
end = time.time()
#break # only look at 0th batch for time
print("error rate %f = %d / %d" % (float(numerr)/total,numerr,total))
if __name__ == '__main__':
exec(open(sys.argv[1]).read())
for aa in sys.argv:
if "EXEC:" in aa:
toexec = aa.replace("EXEC:","")
print("toexec",toexec)
exec(toexec)
print("-------")
print(help(args))
print("-------")
test(args)