10 lines
1 KiB
Python
10 lines
1 KiB
Python
import base64,json
|
|
from pathlib import Path
|
|
import numpy as np
|
|
from model_core import normalize,predict,quantized,CAP,SCALE
|
|
r=Path('/home/user/run/mnist-fast');f=np.load(r/'best.npz');params=[f[k] for k in ['w1','b1','w2','b2']];m=json.loads((r/'model.json').read_text());steps=m['steps'];raw=np.fromfile('/home/user/run/mnist-native-20261015/MNIST.bin',np.uint8).reshape(-1,28,28)[60000:]
|
|
ids=[2534]+list(range(20))+np.random.default_rng(444).choice(10000,64,replace=False).tolist();rows=[];w1,b1,w2,b2=quantized(params)
|
|
for index in ids:
|
|
im=raw[index];x=normalize(im).ravel();drive=np.clip(x.astype(float)@w1.astype(float)+b1,0,m['threshold']);counts=np.floor(drive*steps/m['threshold']).astype(int);scores=(counts.astype(float)@w2.astype(float)*CAP/steps+b2)/SCALE
|
|
rows.append({'test_index':index,'raw':base64.b64encode(im.tobytes()).decode(),'normalized':base64.b64encode(x.tobytes()).decode(),'counts':counts.tolist(),'scores':scores.tolist(),'prediction':int(scores.argmax())})
|
|
(r/'parity-cases.json').write_text(json.dumps({'cases':rows},separators=(',',':'))+'\n')
|