mnist demo improvements#104
Open
ajsenthi wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.