r/MachineLearning • u/chakibmed • 2h ago
Project Reading a blood-pressure monitor with 10,123 parameters (54 KB plain JS, trained only on synthetic digits) [P]
I started a medication that can raise blood pressure and needed to log my readings regularly to see how my body reacted. Good clinical monitors (the kind pharmacists and doctors trust) usually don't have Bluetooth -- just a backlit 7-segment LCD. Typing three numbers every time gets tedious, and because it's medical data, I didn't want cloud OCR, accounts, or third-party health apps holding my history.
So I built BP Log, a zero-dependency offline phone PWA (IndexedDB + Service Worker) that reads systolic, diastolic, and pulse locally from a photo in under 0.3 seconds.
How it went from 40% to 91% whole-reading accuracy on 55 real photos:
- v1 (40%): Basic "three tallest rows" + 7-bar segment check struggled with glare, saturated green backlights, and faint pulse digits.
- Rules + local background subtraction (40% -> 85%): Grey-level closing removes uneven backlight/vignetting across green/yellow/beige LCDs, deskewing (-15° to +15°), layout scoring (mmHg anchor, systolic > diastolic), and per-row threshold retries.
- Tiny CNN trained purely on synthetic data (85% -> 91% whole readings; 95.7% -> 99.5% held-out real digits): Since I only had ~388 real labelled digits from one monitor (with few 4/5/6 examples), I trained a 3-conv + 1-linear CNN (10,123 parameters, 54 KB) exclusively on 150,000 synthetically generated/damaged 7-segment digits (~42s on Apple MPS), keeping all real scans strictly for dev/test evaluation.
- Zero-dependency JS inference: Exported weights as base64 float32 and wrote a ~60-line plain JavaScript forward pass that produces 388/388 identical predictions to PyTorch (max probability delta 1.8e-6), running at ~1 ms/digit (~268 ms/photo end-to-end) on an Android 10 phone.
- Benchmarking lesson: Repeated phone runs initially looked like a memory leak until alternating variants on a cool phone proved it was thermal throttling.
Finding rows under heavy glare is now the main remaining failure mode rather than digit classification. Everything is MIT-licensed, including the 55 real scans and 388 labelled digit crops if anyone wants a small real-world 7-segment benchmark:
- GitHub (code + full write-up): https://github.com/chakib-belgaid/bp-tracker
- Hugging Face dataset: https://huggingface.co/datasets/chakibmed/bp-monitor-seven-segment
Happy to answer questions or hear suggestions on generalizing the row detector across different monitors.

