Built to order

Tuberculosis Detection using Chest X-Rays

A chest X-ray classifier that flags tuberculosis manifestations, built on the two public NLM datasets: Shenzhen (662 films) and Montgomery County (138 films). A DenseNet121 is fine-tuned after U-Net lung-segmentation cropping and evaluated cross-institution (train on one set, test on the other) with the generalization gap documented openly. The demo offers a classifier view, attention overlays and a dataset-comparison view. This is a research prototype, not a medical device. Suitable for B.E./B.Tech final-year projects in Computer Science, AI/ML and Biomedical streams.

Tuberculosis Detection using Chest X-Rays — project thumbnail preview
More project photos (3)

The problem

Tuberculosis still ranks among the top infectious killers, and the chest X-ray is the frontline screening tool where sputum testing is slow or unavailable. The radiographic signs — apical nodules, cavitation, fibrotic streaking — are recognizable but reading thousands of screening films needs trained radiologists who are scarce in high-burden regions. Two public datasets exist precisely for this research, released by the U.S. National Library of Medicine: the Shenzhen set (662 posterior-anterior chest X-rays, 336 TB and 326 normal) and the Montgomery County set (138 films, 58 TB and 80 normal). This project fine-tunes a DenseNet121 on these films, but its real distinguishing feature is methodological: instead of reporting only in-distribution scores, it trains on one institution and tests on the other, confronting the domain-shift problem that decides whether any screening model works in practice. The demo makes this visible with a dedicated cross-dataset comparison view, and the documentation carries the medical-prototype disclaimer throughout.

SYSTEM FLOW

6 components 6 connections

Live flow
Drag to explore
100%
userUser

Uploads a chest X-ray in the classifier view.

Follow the working sequence

How it works

  1. Chest X-rays from the Shenzhen and Montgomery sets are loaded and passed through a U-Net lung segmenter; each film is cropped to its lung ROI.
  2. ROIs are contrast-enhanced with CLAHE, resized to 512x512 and normalized with ImageNet statistics.
  3. Splits are made at the patient level; the cross-institution protocol additionally holds out one entire dataset for testing.
  4. A DenseNet121 backbone (ImageNet weights) with a dropout + sigmoid head trains with class-weighted binary cross-entropy under the AdamW optimizer, head first, then deeper blocks unfrozen.
  5. Augmentation — small rotations, horizontal flips, elastic distortion — is applied during training; every epoch logs validation metrics and the best checkpoint is kept.
  6. Evaluation reports AUC, sensitivity at 90% specificity and F1 both in-distribution and cross-institution.
  7. The demo app serves predictions with attention overlays, the pattern checklist, and the side-by-side dataset comparison view.

Tech stack:

  • Python 3.10, PyTorch with torchvision DenseNet121
  • OpenCV (loading, CLAHE, ROI cropping), NumPy, pandas
  • scikit-learn (patient-level splits, metrics)
  • Matplotlib, Seaborn (training curves, ROC curves)
  • Flask demo app (classifier, attention, dataset-comparison views)
  • Shenzhen TB X-ray set (662 CXRs) + Montgomery County set (138 CXRs), via NLM
Parameter Value
Model DenseNet121 (ImageNet backbone), fine-tuned + dropout/sigmoid head
Task Binary classification: TB manifestation vs normal
Input PA chest X-ray, 512x512 after lung-ROI crop
Preprocessing U-Net lung segmentation, CLAHE, ImageNet normalization
Datasets Shenzhen 662 (336 TB / 326 normal); Montgomery 138 (58 TB / 80 normal)
Loss / optimizer Class-weighted binary cross-entropy; AdamW, two-phase unfreezing
Output P(TB) + attention overlay + pattern checklist
Evaluation AUC, sensitivity at 90% specificity, F1 — in-distribution and cross-institution, computed during the build
Design target Approximately 0.85+ AUC in-distribution (target, not a claimed result)
Demo Flask app with 3 views

Project features

  • [DenseNet121 transfer learning] ImageNet-pretrained DenseNet121 fine-tuned with a two-phase schedule (head first, then deeper dense blocks via AdamW) for TB-vs-normal classification
  • [Lung-segmentation pre-step] U-Net lung masks crop each film to the lung ROI before classification, so the model learns from lung tissue rather than background and annotations
  • [Cross-institution evaluation] Train-on-Shenzhen/test-on-Montgomery protocol (and reverse) with AUC, sensitivity-at-90%-specificity and F1 reported per direction — the honest generalization test
  • [Attention overlays] Grad-CAM-style maps from the final dense block highlight the regions (typically upper lobes) driving each decision
  • [Radiographic pattern checklist] Demo overlay annotating nodules, cavitation, fibrotic streaking, effusion and miliary pattern for teaching purposes
  • [Three-view demo app] Classifier view, attention-map toggle, and a dataset-comparison view showing both collections side by side
  • [512x512 high-resolution pipeline] CLAHE enhancement and ImageNet normalization tuned for the digitized film quality of these sets
  • [Viva-ready documentation] Report with dataset analysis, domain-shift discussion, error analysis and the medical-prototype disclaimer stated explicitly

What is included

  • Complete source code (segmentation, training, evaluation, demo app)
  • Fine-tuned model weights exported from the included training run
  • Jupyter training and evaluation notebook (buyer-run procedure: train, cross-test, evaluate)
  • Project report PDF (background, dataset analysis, domain-shift discussion, evaluation, error analysis, medical-prototype disclaimer)
  • PPT presentation for final review
  • Viva Q&A preparation document (DenseNet, transfer learning, domain shift, metrics)
  • Setup guide (environment, dataset download, training, running the demo)

Advantages

  • ImageNet-pretrained DenseNet121 is fine-tuned with a two-phase schedule (head first, then deeper dense blocks via AdamW) for TB-versus-normal classification.
  • U-Net lung masks crop each film to the lung ROI before classification, so the model learns from lung tissue rather than background and annotations.
  • Cross-institution evaluation trains on Shenzhen and tests on Montgomery County and vice versa, reporting AUC, sensitivity-at-90%-specificity and F1 per direction, the honest generalization test.
  • Grad-CAM-style maps from the final dense block highlight the regions, typically upper lobes, driving each decision.
  • The demo offers a classifier view, an attention-map toggle, and a dataset-comparison view showing both collections side by side, built on the Shenzhen set of 662 films and the Montgomery County set of 138 films.
  • The pipeline runs at 512x512 resolution with CLAHE enhancement and ImageNet normalization tuned for the digitized film quality of these sets.

Disadvantages

  • This is an academic research prototype, not a medical device: TB diagnosis requires sputum testing such as CBNAAT and a radiologist, and this system never replaces that pathway.
  • No AUC or sensitivity figure is promised: cross-institution scores are expected to be lower than in-distribution ones, and the report documents the measured gap honestly.
  • The two datasets are small by deep-learning standards (800 films combined) and come from specific screening programs, so performance on other populations is unvalidated.
  • The model outputs a film-level score, not a localized diagnosis, and it does not type TB manifestations such as cavitation versus effusion in the base build.
  • Digitized-film artifacts and pediatric cases in the Shenzhen set add noise that bounds achievable performance.

Limitations & prerequisites

  • This is an academic research prototype, not a medical device: TB diagnosis requires sputum testing (e.g. CBNAAT) and a radiologist; this system never replaces that pathway.
  • No AUC or sensitivity figure is promised: cross-institution scores are expected to be lower than in-distribution ones, and the report documents the measured gap honestly.
  • The two datasets are small by deep-learning standards (800 films combined) and come from specific screening programs; performance on other populations is unvalidated.
  • The model outputs a film-level score, not a localized diagnosis; it does not type TB manifestations (cavitation vs effusion) in the base build.
  • Digitized-film artifacts and pediatric cases in the Shenzhen set add noise that bounds achievable performance.

Frequently Asked Questions

Which datasets are used?

Two public NLM collections: the Shenzhen set (662 PA chest X-rays — 336 TB, 326 normal, from Shenzhen No.3 People's Hospital) and the Montgomery County set (138 films — 58 TB, 80 normal, from the Maryland TB-control screening program). Both are freely available for research.

What is cross-institution evaluation, and why does it matter?

Training on Shenzhen and testing on Montgomery (and vice versa) measures whether the model learned TB patterns or just one hospital's scanner characteristics. Scores almost always drop across institutions; documenting that drop honestly is the central methodological contribution of this build.

Is the accuracy guaranteed?

No. The design target is approximately 0.85+ AUC in-distribution, but every figure — AUC, sensitivity at 90% specificity, F1, per-direction scores — is computed by the training notebook during the build and reported with the gap between in-distribution and cross-institution results.

Is this a medical device? Can it diagnose TB?

No. This is an educational research prototype. TB diagnosis needs microbiological confirmation and a qualified radiologist; this system produces an assistive score only and is never a substitute for clinical diagnosis.

Why the lung-segmentation step?

Raw films contain shoulders, text annotations and collimation edges that a classifier can latch onto as shortcuts. Cropping to the U-Net lung ROI forces the model to decide from lung tissue, which the report demonstrates with ablation-style discussion.

Can it distinguish TB from pneumonia or COVID patterns?

Not in the base build — it is a TB-vs-normal classifier on these two datasets. Multi-condition classification is documented future scope and would need additional labeled data. Suitable for B.E./B.Tech final-year projects in Computer Science, AI/ML and Biomedical streams.

Components & software requirements
  • Python 3.10, PyTorch with torchvision DenseNet121
  • OpenCV (loading, CLAHE, ROI cropping), NumPy, pandas
  • scikit-learn (patient-level splits, metrics)
  • Matplotlib, Seaborn (training curves, ROC curves)
  • Flask demo app (classifier, attention, dataset-comparison views)
  • Shenzhen TB X-ray set (662 CXRs) + Montgomery County set (138 CXRs), via NLM
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download free synopsis (PDF)

Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.

Jaeger et al. (2014) Automatic tuberculosis screening using chest radiographs, IEEE Trans. Medical Imaging 33, 233-245

Related guides

All guides

YOLO Object Detection for Final-Year Projects: Datasets, Colab Training, mAP and Deployment

How do you build a YOLO object detection project for your final year? Start with a labelled dataset in YOLO format (300-500+ images per class with real variation), train a small pretrained model on Google Colab with early stopping, evaluate with mAP@0.5 and mAP@0.5:0.95 on a held-out test set, and deploy the exported model on your demo hardware. This guide covers the full pipeline - version choice, labelling discipline, Colab training, honest evaluation, common errors, and deployment - with the decision tables and checklists your report needs.

Read guide

GANs Explained: How Generators and Discriminators Train Together

You have heard of AI that generates images and synthetic datasets. Behind much of that sits the GAN: two neural networks locked in a game where one creates fakes and the other learns to catch them. This guide explains the adversarial game, the minimax loss, a minimal DCGAN you can train yourself, and the classic failure modes and their fixes.

Read guide

Machine Learning Final Year Project Ideas with Datasets

This guide lists 30+ machine learning final-year project ideas grouped by type — tabular prediction, NLP, computer vision, and time series — each paired with a well-known public dataset from the UCI ML Repository or Kaggle. Pick a dataset with 1,000 to 50,000 rows: large enough to train a real model, small enough to iterate on a laptop. Confirm the license allows academic use and that it has a clear target column. Build a baseline model in week 1 so you always have something working. Avoid collecting your own dataset unless you have 2+ months to spare.

Read guide
Get a quotation