"""Prepare the original model's exact train prefix plus the new held-out test.""" from pathlib import Path import numpy as np root = Path('/home/int/run/cats-dogs') raw = np.load(root / 'data-v2/test-original.npz') rgb = raw['rgb'].reshape(-1, 3, 32, 32).astype(np.float32) gray = (299 * rgb[:, 0] + 587 * rgb[:, 1] + 114 * rgb[:, 2]) / 1000 padded = np.pad(gray, ((0, 0), (2, 2), (2, 2)), mode='edge') blur = sum(padded[:, y:y+32, x:x+32] for y in range(5) for x in range(5)) / 25 contrast = (gray - blur) * 4 encoded = np.concatenate([np.clip(contrast, 0, 255).reshape(-1, 1024), np.clip(-contrast, 0, 255).reshape(-1, 1024)], axis=1).astype(np.uint8) with (root / 'features-v2/baseline_test.bin').open('wb') as out: out.write((root / 'data/contrast_train.bin').read_bytes()) out.write(encoded.tobytes()) y = np.concatenate([np.loadtxt(root / 'data/train.target', dtype=int), raw['labels']]) np.savetxt(root / 'features-v2/baseline_test.target', y, fmt='%d') print('Original train prefix and fresh test encoded', flush=True)