Research & Engineering

Making whole-slide pathology images machine-learning-friendly

A single whole-slide pathology image — the kind a pathologist examines to diagnose cancer — can be 100,000 by 100,000 pixels. Uncompressed, that's around 30 gigabytes for one slide. A typical research study might involve anywhere from ten to ten thousand of them.

That scale is exactly what makes these images hard to use for machine learning. Popular frameworks like TensorFlow are built around much smaller images — a few hundred pixels a side. To train or run a model on a whole-slide image, you have to break it into tiles, and depending on tile size, a single slide can produce anywhere from thousands to millions of them. It sounds like a data-plumbing problem. It turns out to be the bottleneck.

Where the time actually goes

Working with the team at Kitware — Lee A. Newberg and Matt McCormick in particular, alongside Lee Cooper's group at Northwestern — the question we kept coming back to wasn't "how do we build a better model." It was "why is reading the data slower than running the model on it."

Existing tools like openslide and large_image are genuinely good at reading whole-slide formats efficiently. But they weren't built to hand data directly into a TensorFlow training loop. The common workaround — pre-slicing a slide into thousands of individual PNG or JPG tiles on disk — works, but it's wasteful: change your tile size and you re-tile everything; use lossy formats and you introduce compression artifacts you didn't ask for.

What we built

HistomicsStream reads whole-slide image data directly into a TensorFlow execution graph, in chunks rather than tile-by-tile, and lets TensorFlow's own scheduling and parallelism handle the rest. In our benchmark — a 19,784 × 27,888 pixel slide, broken into 256 × 256 tiles — throughput went from 16.9 tiles per second to 27.9, a 65% improvement, on the same GPU.

It's a narrow piece of infrastructure. It doesn't diagnose anything by itself. But it sits at the very start of the pipeline for tools like HistomicsTK and the Digital Slide Archive, and if it's slow, everything downstream is slow. This work was funded through an NIH National Cancer Institute grant with Northwestern, Wake Forest School of Medicine, and Emory University as collaborating institutions.

The lesson that stuck with me: in applied ML, the unglamorous infrastructure work — getting data in front of the model efficiently — is very often the actual bottleneck, not the modeling itself.

We wrote up the full technical details on Kitware's blog, and the code is public if you want to see how it's put together.

← Back to blog