None
None
None

On many hospital nights, the story begins the same way.

A patient sits propped up in bed, oxygen cannula at their nostrils, breathing just a little too fast. Somewhere down the hall, a portable X-ray machine hums, the film is exposed, and minutes later a chest radiograph blooms on a screen: a pair of lungs, frozen mid-breath, asking a question.

Is this normal?

Or is it tuberculosis? Pneumonia? COVID-19?

The human eye has been answering that question for more than a century. But what if a machine could sit beside the radiologist, not to replace that eye, but to accompany it? To say, quietly:

"Look here. This region worries me."

This is the story of how, over one focused weekend, I built and deployed a small model that does exactly that — and how a technique called Adaptive Sparse Training (AST) made it both powerful and light enough to be trained on a single GPU in my home studio.

The model lives here now:

👉 https://huggingface.co/spaces/mgbam/Tuberculosis

It looks at a chest X-ray and chooses among four possibilities:

  • Normal
  • Tuberculosis (TB)
  • Pneumonia
  • COVID-19

And at its best checkpoint, at Epoch 83, it learned to see with surprising clarity:

  • Normal: 88.22%
  • TB: 98.10%
  • Pneumonia: 97.56%
  • COVID-19: 88.44%

Numbers alone don't tell the story. To understand how this came to be, we have to step back, to code, to energy, and to the philosophy behind how we teach machines to pay attention.

A Small Room, a Single GPU, and Too Many Lungs

The setting was not glamorous.

A desk. A chair. A laptop tethered to a single GPU humming steadily. Outside, the weekend went about its business; inside, my screen filled with lungs.

Rows of X-rays, each a different story:

  • Some clean, the ribs arching like gentle parentheses around clear fields.
  • Some streaked with white, the fingerprints of pneumonia.
  • Some mottled, diffuse — the familiar fog of COVID-19.
  • Some with deeper scars, cavities etched into the upper lobes, whispering tuberculosis.

I had built a medical AI system before, for malaria diagnosis. That project left me with two convictions:

  1. AI can help where resources are thin.
  2. If AI demands enormous energy and hardware, it will never reach those places.

So when I turned to chest X-rays, I brought with me more than just a model architecture. I brought a training philosophy: don't waste computation. Use only what you need.

That philosophy has a name: Adaptive Sparse Training.

Why AST Matters: The Art of Leaving Neurons Alone

Most deep learning today behaves like a hospital that turns every light on for every patient, all the time.

Take a standard network: millions of parameters, all firing, all participating at every training step, regardless of whether they are truly needed for a particular image. It works — but it is extravagant, the digital equivalent of leaving the CT scanner running just to read a stethoscope.

Adaptive Sparse Training (AST) asks a quieter question:

"What if only a few of these neurons truly need to wake up for each example?"

AST is the technique I maintain as an open-source library on PyPI (pip install adaptive-sparse-training). At its heart is a gating mechanism my Sundew algorithm that learns to switch neurons on and off dynamically, like a plant that opens only the leaves it needs to catch the sun.

In practice, AST works like this:

  1. Start Dense, Learn the Landscape At the beginning of training, the network uses its full capacity. Every neuron gets a chance to contribute, like a new team in which everyone attends every meeting.
  2. Learn Importance As training progresses, the Sundew gates begin to notice patterns: These neurons are doing real work. Those are mostly noise.
  3. Grow Sparse, Stay Smart The network gradually quiets the least useful neurons. By the time sparsity stabilizes, only a fraction — sometimes as low as 15–20% — are truly active for a given sample.
  4. Preserve Accuracy, Slash Energy Because the pruning is learned, not random, the model keeps its accuracy while lowering the computation needed for each forward and backward pass.

On the malaria project, AST led to about 88% energy savings during training without sacrificing diagnostic performance.

For the chest X-ray model, I reused that same AST engine, this time in service of a harder question: four diseases and a normal class, all in a single shot.

The goal was not only to train a capable model, but to prove that such a model could be born and refined without a rack of GPUs — just a single device, the way a small lab, a teaching hospital, or a determined student might have to do it.

Teaching a Model to Read Four Stories in One Image

The dataset was a chorus of lungs. Some labeled Normal, some TB, some Pneumonia, some COVID-19. I split, shuffled, and prepared them for what would essentially be an accelerated medical school for a neural network.

The curriculum looked like this:

  • Architecture: a modern convolutional network, chosen for efficiency and compatibility with sparsity.
  • Task: four-class classification — a kind of differential diagnosis in pixel space.
  • Training:
  • Augmentations to mimic real practice: small rotations, flips, brightness changes.
  • Careful class balancing to prevent the model from favoring the most common diagnoses.
  • AST to tame the network's appetite for computation.

Epoch after epoch, the model sat with these images the way a trainee might sit with a senior radiologist: looking, guessing, being corrected, trying again.

What made this different from a conventional training loop was the presence of AST. It was as though, midway through its training, the model realized:

"I don't need all of this. This pathway sees nothing useful. That cluster, though — that one recognizes the upper-lobe scarring of TB. Keep that."

By the time the training run reached Epoch 83, the network had become lean and opinionated. Its internal conversations, if we could hear them, might have sounded like this:

  • This diffuse, bilateral opacity with ground-glass areas? I've seen that in COVID-19.
  • These lobar consolidations, this air bronchogram? Pneumonia, most likely.
  • Thin, clear fields and no suspicious shadows? Probably normal.
  • Thickening and cavities near the apices, the roof of the lungs? Think TB.

When I computed the per-class accuracy, I felt the quiet satisfaction that radiologists feel when a complex case makes sense in retrospect:

  • Normal: 88.22%
  • TB: 98.10%
  • Pneumonia: 97.56%
  • COVID-19: 88.44%

These are not perfect numbers. But they are, importantly, honest ones — the result of a model that had to work within the constraints of a single GPU and a finite amount of energy.

Opening the Black Box: Showing Where the Model "Looks"

No clinician should be asked to trust a classification without a reason.

So I added another layer to the system: Grad-CAM, an explainability method that generates heatmaps over the X-ray to show where the model's attention concentrated.

When you open the Hugging Face Space and upload an image, you don't just see:

"TB: 0.981, Pneumonia: 0.012, COVID-19: 0.004, Normal: 0.003."

You see:

  • The original X-ray
  • The predicted probabilities for all four classes
  • A heatmap glowing over the parts of the lung fields that influenced the decision most

It's the difference between a student saying, "I think this is TB," and a seasoned clinician asking gently, "Show me why."

In medicine, where stakes are measured in lives, explanations matter as much as predictions.

What This Could Mean at the Bedside

It is tempting, when talking about AI, to live entirely in plots and metrics. But the true test of a system like this is in imagined scenes that feel real.

In a crowded clinic

A clinician sees twenty chest X-rays in an afternoon. A simple interface running this model could:

  • Sort the stack by predicted severity.
  • Highlight cases likely to represent TB or pneumonia.
  • Give the overworked human a prioritized list of scans to review first.

The final decision remains firmly human. But now the human has a tireless assistant who never gets bored, never loses concentration at 3 a.m.

In a teaching hospital

Residents could upload anonymized cases, ask the model for its opinion, and then compare:

  • Where did I see pathology?
  • Where did the model see it?

Disagreements become lessons, not threats.

In resource-limited settings

Because AST keeps the training efficient, the same philosophy can extend to deployment on modest hardware. The long-term vision is a model that doesn't insist on living in a data center, but can reside closer to the point of care — in smaller hospitals, teaching centers, eventually even on edge devices.

A Word to the Skeptical Clinician and the Exacting Engineer

If you are a radiologist, pulmonologist, or infectious disease specialist, you might read this with folded arms and a raised eyebrow. You're right to be cautious.

This system is:

  • Not FDA-approved
  • Not a substitute for your judgment
  • Not a license to ignore clinical context

Consider it instead a prototype triage companion, a proof that:

One person, a publicly available dataset, an energy-aware training method, and a single GPU can produce a four-class chest X-ray model that genuinely knows something about disease patterns.

If you are an ML engineer, you might ask for more detail:

  • How exactly are the AST gates parameterized?
  • What sparsity schedule was used?
  • How is the trade-off between sparsity and accuracy tuned?

Those questions belong to a technical appendix and a GitHub repository — both of which I plan to expand. For now, the core message is simply this:

AST is not an abstract research idea. It is running, today, inside a real medical imaging model, quietly lowering the energy bill of learning.

Open Source as an Act of Faith

I chose to release not just the model, but the training philosophy behind it, as open source:

Open sourcing is a kind of trust fall. You hand your careful work to strangers and say:

"Here. Critique this. Improve it. Break it and show me how to make it stronger."

But it is also the only way I know to make sure that tools like this don't stay locked inside one machine, one institution, or one country.

Where This Goes Next

This model is not the culmination of a career. It is an early chapter.

The road ahead includes:

  • Clinical validation with real-world data beyond the training set
  • Bias analysis to ensure performance holds across patient populations
  • Model refinement: new architectures, better pretraining, richer labels
  • Edge-friendly deployment, so that the model can live on smaller, cheaper devices

And above all, it includes collaboration:

  • If you are a clinician, I want your skepticism, your red pen, your annotated cases.
  • If you are an engineer, I want your pull requests, your bug reports, your ideas for making AST even more agile.
  • If you are simply someone who cares about health and technology, I want your questions — they keep the work honest.

The Quiet Hope Inside best.pt

In the end, all of this — the late nights, the training logs, the sparsity schedules, the per-class accuracies — settles into a small file named best.pt.

It sits there with no fanfare, a few megabytes in a repository. You could almost miss it.

But inside are:

  • The distilled memory of thousands of chest X-rays
  • A set of weights that have learned to separate Normal, TB, Pneumonia, and COVID-19 with real competence
  • A training story in which Adaptive Sparse Training allowed the model to learn more by using less

Perhaps one day, a descendant of this file will be running silently in a hospital server somewhere, helping a clinician catch a case of TB a little sooner, or nudging a tired resident to take a second look at a subtle pneumonia.

If that happens, it will be because a machine learned not only to look, but to look carefully — and because we taught it to do so with respect for the precious resource that underlies all computing and all clinical work: attention.

Human, or artificial, it is the same.