One-line recap: the model scored 97% on cleaned-up images and 78% on real scanner images, because it learned the photo cleanup instead of the biology.
The obvious fix: feed it more scanner images. The obvious fix was wrong.
The right fix started with a question most people skip: what actually IS a stained microscope image?
Two dyes, one light source, known math
A standard tissue slide carries exactly two dyes. One clings to cell nuclei and stains them blue-purple. The other clings to everything else and stains it pink-red. Light passes through the thin slice; each dye absorbs its share.
That is a physical process with equations. So "different scanner, different colors" is not a mystery — it is the same two dyes through a slightly different lens and light.
So instead of more photos, the training itself became physical: every image gets split into its two dye amounts, nudged within realistic limits, and rebuilt. The model now sees the same tissue wearing every scanner's clothes.
Tests written BEFORE the fix existed
This ordering matters: you cannot write an honest exam for a thing you already built — you will unconsciously write an exam it already passes. Five tests came first. Three designs of the color system died before one passed all of them:
- Coverage. A scanner the tool never saw — the adjustments must cover its quirks.- Stays real. A second small network, trained to spot fakes, must not tell adjusted images from real ones.- Exact physics. Cut one dye's strength in half; the measured output must come back at exactly half — nothing leaking into the other dye.- Identity. Adjustments at zero must return the original image, pixel for pixel. ## And the boring problem that decided everything: speed The first working version spent about 19 milliseconds per image splitting dyes. Across 200,000 training images, that is the difference between a training run taking all day and taking an hour. The math was rebuilt to solve directly instead of guess-and-correct, plus a cache so each image is split once: about 6 milliseconds. Same answers, three times faster. ## The score After retraining: the model now scores higher on real scanner images than on the cleaned benchmark that originally fooled it. The cleanup trap is closed. But every fix sends a bill somewhere. The next post is the one where a fix solved one problem and quietly broke another guard. That is the discipline: after every change, measure the whole scoreboard — not just the number you were fixing. Live demo (runs on my own GPU): histogate.vercel.app · Weights and full measured results are public: huggingface.co/riju279/histogate · Everything else: github.com/hr1juldey/histogate