Skip to content

Commit

Permalink
Fix parsing of percentage numbers in test output
Browse files Browse the repository at this point in the history
wilrich-msft committed Jun 10, 2016
1 parent db06861 commit a261c75
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion contrib/Python/cntk/context.py
Original file line number Diff line number Diff line change
@@ -600,7 +600,13 @@ def _parse_test_result(output):
if '*' in v:
v = v.split('*')[0].strip()

result[k.strip()] = float(v)
if v[-1] == '%':
# In some cases, CNTK outputs data in percentage
v = float(v[:-1])/100
else:
v = float(v)

result[k.strip()] = v

return result

13 changes: 12 additions & 1 deletion contrib/Python/cntk/tests/context_test.py
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ def test_parse_eval_result_output_2():
assert np.isinf(data[7]) and data[7] < 0


def test_parse_test_result_output():
def test_parse_test_result_output_1():
output = '''\
Final Results: Minibatch[1-1]: eval_node = 2.77790430 * 500; crit_node = 0.44370050 * 500; perplexity = 1.55846366
'''
@@ -110,6 +110,17 @@ def test_parse_test_result_output():
assert result['crit_node'] == 0.44370050
assert len(result) == 3

def test_parse_test_result_output_2():
output = '''\
Final Results: Minibatch[1-1]: loss = 47.3% * 500; crit_node = 0.44370050 * 500; perplexity = 1.55846366
'''
result = LocalExecutionContext._parse_test_result(output)

assert result['perplexity'] == 1.55846366
assert result['loss'] == 0.473
assert result['crit_node'] == 0.44370050
assert len(result) == 3

def test_export_deferred_context():
X = Input(2)
reader = CNTKTextFormatReader("Data.txt")

0 comments on commit a261c75

Please sign in to comment.