-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.py
75 lines (66 loc) · 3.04 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
# run this as test? https://cmake.org/pipermail/cmake/2010-August/039174.html
import multiHypoTracking_with_gurobi as mht
# set up a test model
weights = {"weights": [10, 10, 10, 500, 500]}
graph = {
"settings": {
"statesShareWeights": True,
"nonNegativeWeightsOnly": True
},
"segmentationHypotheses": [
{
"id": 2,
"features": [[1.0], [0.0]],
"divisionFeatures": [[0.0], [-5.0]],
"appearanceFeatures": [[0], [0]],
"disappearanceFeatures": [[0], [50]],
"timestep": [1, 1]
},
{"id": 3, "timestep": [1, 1], "features": [[1.0], [0.0]], "divisionFeatures": [
[0], [-5]], "appearanceFeatures": [[0], [0]], "disappearanceFeatures": [[0], [50]]},
{"id": 4, "timestep": [2, 2], "features": [[1.0], [0.0]], "appearanceFeatures": [
[0], [50]], "disappearanceFeatures": [[0], [-2]]},
{"id": 5, "timestep": [2, 2], "features": [[1.0], [0.0]], "appearanceFeatures": [
[0], [50]], "disappearanceFeatures": [[0], [-2]]},
{"id": 6, "timestep": [2, 2], "features": [[1.0], [0.0]], "appearanceFeatures": [
[0], [50]], "disappearanceFeatures": [[0], [-4]]}
],
"linkingHypotheses": [
{"src": 2, "dest": 4, "features": [[0], [-4]]},
{"src": 2, "dest": 5, "features": [[0], [-3]]},
{"src": 3, "dest": 5, "features": [[0], [-1]]},
{"src": 3, "dest": 6, "features": [[0], [-4]]}
]
}
expectedResult = {'detectionResults': [{'id': 2, 'value': 1},
{'id': 3, 'value': 1},
{'id': 4, 'value': 1},
{'id': 5, 'value': 1},
{'id': 6, 'value': 1}],
'divisionResults': [{'id': 2, 'value': 1},
# {'id': 3, 'value': 0},
# {'id': 4, 'value': 0},
# {'id': 5, 'value': 0},
# {'id': 6, 'value': 0}
],
'linkingResults': [{'dest': 4, 'src': 2, 'value': 1},
{'dest': 5, 'src': 2, 'value': 1},
# {'dest': 5, 'src': 3, 'value': 0},
{'dest': 6, 'src': 3, 'value': 1}]
}
# test tracking
res = mht.track(graph, weights)
del res['resultEnergy']
assert(res == expectedResult)
# test validation
assert(mht.validate(graph, expectedResult))
# test traininig
learnedWeights = mht.train(graph, expectedResult)
assert('weights' in learnedWeights)
assert(len(learnedWeights['weights']) == 5)
assert(not any(w < 0 for w in learnedWeights['weights']))
# test traininig with initialization
learnedWeights = mht.trainWithWeightInitialization(graph, expectedResult, learnedWeights)
assert('weights' in learnedWeights)
assert(len(learnedWeights['weights']) == 5)
assert(not any(w < 0 for w in learnedWeights['weights']))