File size: 1,805 Bytes
ef987bb | 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 | import pathlib
import re
import struct
root = pathlib.Path.cwd()
img_path = root / 'train-images-idx3-ubyte'
label_path = root / 'train-labels-idx1-ubyte'
assert img_path.exists(), 'missing train-images-idx3-ubyte fixture'
assert label_path.exists(), 'missing train-labels-idx1-ubyte fixture'
magic, count, rows, cols = struct.unpack('>IIII', img_path.read_bytes()[:16])
assert (magic, count, rows, cols) == (2051, 10, 8, 8), 'unexpected tiny MNIST image header'
lmagic, lcount = struct.unpack('>II', label_path.read_bytes()[:8])
assert (lmagic, lcount) == (2049, 10), 'unexpected tiny MNIST label header'
report_path = root / 'report.html'
assert report_path.exists() and report_path.stat().st_size > 0, 'missing report.html'
report = report_path.read_text(encoding='utf-8', errors='ignore').lower()
for token in ['mnist', 'mlp']:
assert token in report, f'report missing {token}'
assert 'f1' in report, 'report missing f1'
assert 'acc' in report or 'accuracy' in report, 'report missing accuracy/acc'
assert (
'80/20' in report
or '4:1' in report
or ('80%' in report and '20%' in report)
or ('0.8' in report and '0.2' in report)
), 'report missing 80/20 split evidence'
numbers = [float(x) for x in re.findall(r'(?<![\w.])(?:0(?:\.\d+)?|1(?:\.0+)?)(?![\w.])', report)]
assert any(0 <= n <= 1 for n in numbers), 'report missing normalized metric value'
# Parse labeled metrics required by the task. No unpublished score floor is imposed.
acc_vals = [float(m) for m in re.findall(r'(?:accuracy|acc)\s*[:=]?\s*(\d+(?:\.\d+)?)', report)]
f1_vals = [float(m) for m in re.findall(r'f1[\w ]*?\s*[:=]?\s*(\d+(?:\.\d+)?)', report)]
assert acc_vals, 'report missing a labeled accuracy/acc metric value'
assert f1_vals, 'report missing a labeled f1 metric value'
|