examples/ is based on KasperskyLab/knp at 55470ed6 with local changes to the mnist-learn altai/blifat models, cuda-backend CMake and model_loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
1.3 KiB
Python
24 lines
1.3 KiB
Python
"""Bounded model selection using real KNP only; test data are never evaluated here."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
root = Path('/home/int/run/cats-dogs')
|
|
script = Path('/mnt/c/KNP/cats-dogs/run.py')
|
|
rows = []
|
|
for encoding, thresholds in [('brightness', [10, 20, 40, 60]),
|
|
('contrast', [10, 20, 40, 60, 100, 150])]:
|
|
for threshold in thresholds:
|
|
name = 'validation' if encoding == 'brightness' and threshold == 60 else f'val_{encoding}_{threshold}'
|
|
dataset = 'validation' if encoding == 'brightness' else 'contrast_validation'
|
|
if not (root / name / 'metrics.json').exists():
|
|
subprocess.run([sys.executable, str(script), name, '--dataset', dataset,
|
|
'--train', '800', '--count', '200', '--threshold', str(threshold)], check=True)
|
|
metrics = json.loads((root / name / 'metrics.json').read_text())
|
|
rows.append(dict(encoding=encoding, threshold=threshold, run=name, **metrics))
|
|
best = max(rows, key=lambda row: row['accuracy'])
|
|
selection = {'method': '10 fixed configurations evaluated with real KNP on validation only; first wins ties',
|
|
'rows': rows, 'selected': best}
|
|
(root / 'selection.json').write_text(json.dumps(selection, indent=2) + '\n')
|
|
print('SELECTED', json.dumps(best), flush=True)
|