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 (2)

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.

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)

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 abstract (PDF)

Related guides

All guides
Blueprint-style technical illustration of multiple decision trees voting together into one final predictionStudents with basic Python and pandas skills who want a reliable first classifier for ML coursework and tabular data projects.

Random Forests Explained: Why Decision Trees Vote Better Together

Decision trees are readable but overfit; random forests fix this by training hundreds of varied trees on bootstrapped data with random feature subsets, then letting them vote. This guide explains Gini impurity, bagging, out-of-bag validation and the four hyperparameters that matter, with a complete scikit-learn workflow, honest feature-importance practices, and the mistakes students keep making.

Read guide
Illustration of object tracking showing video frames with bounding boxes and persistent ID labels following people and vehicles, comparing motion prediction and appearance matching.B.E./B.Tech Computer Science and Electronics students building video analytics projects — people counting, vehicle tracking, sports analysis — who have detection working and need

Object Tracking: DeepSORT and ByteTrack Explained

Detection finds objects per frame; tracking keeps their identities across frames. This guide explains tracking-by-detection, Kalman motion models, DeepSORT's appearance embeddings vs ByteTrack's low-confidence box recovery, tracking metrics (HOTA, IDF1, ID switches), and the tuning parameters that determine real-world quality.

Read guide
Illustration of image segmentation showing U-Net's U-shaped encoder-decoder with skip connections producing pixel masks, alongside Mask R-CNN detecting instances with masks.B.E./B.Tech Computer Science and AI/ML students moving from image classification or detection to pixel-level understanding — medical imaging, defect detection, autonomous driving

Image Segmentation: U-Net and Mask R-CNN

When projects need pixel-level answers, segmentation delivers. This guide explains semantic vs instance vs panoptic segmentation, U-Net's encoder-decoder with skip connections, Mask R-CNN's parallel mask head, Dice and IoU evaluation, paired augmentation, and how to choose the right architecture for your data and question.

Read guide
Get a quotation