-
Notifications
You must be signed in to change notification settings - Fork 2
/
Evaluate.py
73 lines (60 loc) · 2.71 KB
/
Evaluate.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
#!/usr/bin/python3
import sys
import settings.EvaluationSettings as evalSettings
from src.Classifier import Classifier
from src.Evaluator import *
import time
def PrintHelp():
print("Usage: Evaluate.py $(PATH_TO_DATA_SET_CATELOG) $(Threshold)")
print(" or, Evaluate.py $(PATH_TO_DATA_SET_CATELOG)")
print(" to find the best threshold.")
def PrintResults(loss_, frameAccuracy_, isThresholdOptimized_, threshold_, videoAccuracy_, duration_):
floatPrecision = "{0:.4f}"
if isThresholdOptimized_:
print("\t loss:", floatPrecision.format(loss_),
" frame accuracy:", floatPrecision.format(frameAccuracy_),
" best frame threshold:", threshold_,
" video accuracy:", floatPrecision.format(videoAccuracy_),
" duration:", "{0:.2f}".format(duration_) + "(s)\n" )
else:
print("\t loss:", floatPrecision.format(loss_),
" frame accuracy:", floatPrecision.format(frameAccuracy_),
" given frame threshold:", threshold_,
" video accuracy:", floatPrecision.format(videoAccuracy_),
" duration:", "{0:.2f}".format(duration_) + "(s)\n" )
if __name__ == '__main__':
numberOfArguments = len(sys.argv)
if (numberOfArguments ==2)or(numberOfArguments==3):
PATH_TO_DATA_SET_CATELOG = sys.argv[1]
classifier = Classifier()
classifier.Build()
evaluator = Evaluator("evaluate", PATH_TO_DATA_SET_CATELOG, classifier)
with tf.Session() as session:
init = tf.global_variables_initializer()
session.run(init)
print("Load Model from: ", evalSettings.PATH_TO_MODEL_CHECKPOINTS)
modelLoader = tf.train.Saver()
modelLoader.restore(session, evalSettings.PATH_TO_MODEL_CHECKPOINTS)
startEvaluateTime = time.time()
if numberOfArguments == 2:
print("Start evaluate: ", PATH_TO_DATA_SET_CATELOG, ", and find the best threshold...")
loss, frameAccuracy, threshold, videoAccuracy = evaluator.Evaluate( session,
currentEpoch_=0,
threshold_=None)
endEvaluateTime = time.time()
PrintResults(loss_=loss, frameAccuracy_=frameAccuracy, isThresholdOptimized_=True,
threshold_=threshold, videoAccuracy_=videoAccuracy,
duration_=(endEvaluateTime-startEvaluateTime) )
else:
threshold = int(sys.argv[2])
print("Start evaluate: ", PATH_TO_DATA_SET_CATELOG, ", with threshold : ", threshold)
loss, frameAccuracy, threshold, videoAccuracy = evaluator.Evaluate( session,
currentEpoch_=0,
threshold_=threshold)
endEvaluateTime = time.time()
PrintResults(loss_=loss, frameAccuracy_=frameAccuracy, isThresholdOptimized_=False,
threshold_=threshold, videoAccuracy_=videoAccuracy,
duration_=(endEvaluateTime-startEvaluateTime) )
evaluator.Release()
else:
PrintHelp()