Skip to content

mnist demo improvements#104

Open
ajsenthi wants to merge 5 commits into
royshadmon:mainfrom
ajsenthi:feat/mnist-demo-improvements
Open

mnist demo improvements#104
ajsenthi wants to merge 5 commits into
royshadmon:mainfrom
ajsenthi:feat/mnist-demo-improvements

Conversation

@ajsenthi

@ajsenthi ajsenthi commented Jun 29, 2026

Copy link
Copy Markdown

MNIST Demo Improvements — accuracy & inference improvements

Fixes several bugs degrading training accuracy and canvas inference quality in the MNIST federated learning demo.

store_data.py

Stratified data loading
Replaced sequential loading with per-class stratified sampling (both train and test sets) to eliminate label bias from MNIST's sorted order.

custom_data_handler.py

Training pipeline
Normalization: moved /255.0 into load_dataset(); preprocess() now only casts dtype.
Query: removed WHERE round_number filter — each round now trains on all available data (LIMIT 1000 train / LIMIT 200 test).
Regularization: added Dropout(0.25) after each conv block and Dropout(0.5) before output.
Class weights: compute_class_weight('balanced') applied per round to handle class imbalance.
Hyperparameters: batch size 128→32, epochs 1→5, EarlyStopping patience set to 5.
Inference endpoint: direct_inference() now normalizes raw 0–255 input automatically.
Evaluation: replaced val_accuracy with run_inference() against TEST_TABLE after each round.

InputDataSelector.js

Canvas brush
Changed from 1×1 pixel brush to a 5-cell cross pattern, better matching MNIST stroke width.

InferPage.js

Canvas preprocessing
Added centerAndScale(): fits drawn digit into 20×20 region, centered on 28×28 grid.
Added gaussianBlur(): 3-pass blur + max-normalization to smooth binary canvas output.

Test results

JSON (normalized 0–255), 30-sample set: ~92%, originally was ~68%, about 24% improvement.
Canvas — all digits 0–9 ✓, testing done by hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants