Researchers have unveiled a hybrid artificial intelligence framework that detects tuberculosis on chest X-rays with exceptionally high accuracy, and they have done so while confronting one of the quietest problems in medical machine learning: data leakage. The new model, called TBFuseFormer, combines two complementary ways of seeing an image — a hierarchical vision transformer that focuses on local structure, and a pretrained global feature encoder — and merges them through a channel attention mechanism before making a binary decision between normal and tuberculosis-positive radiographs. In a study published in Discover Analytics, the team reports a five-fold cross-validation accuracy of 99.51 plus or minus 0.12 percent after optimization and a held-out test accuracy of 99.39 percent, outperforming independently tuned versions of Swin Transformer V2 Base, ConvNeXt V2 Base, and standalone DINOv2.
The leakage concern is not a technical footnote. When datasets are stitched together from multiple public repositories, duplicate or near-duplicate images can slip into both training and evaluation partitions, allowing a model to effectively memorize answers it has already seen. The result is an inflated performance estimate that collapses the moment the model meets genuinely new data. The researchers treated deduplication as a core scientific safeguard rather than a preprocessing afterthought. Their raw aggregate of 8,008 chest radiographs, drawn from three sources — a Qatar University and University of Dhaka collection hosted on Kaggle, a Pakistan TB Chest X-rays dataset from Mendeley, and the combined Shenzhen and Montgomery collections from NIH/IHNCBC — was screened in four sequential stages.
First, exact byte-level duplicates were caught using SHA-256 hashing, removing 85 images. Next, visually identical images were detected with average hashing at a Hamming distance of zero, eliminating 71 more. A perceptual hashing stage based on the discrete cosine transform, with a Hamming distance threshold of six or fewer bits out of 64, removed 100 near-duplicates. Finally, deep feature screening using DINOv2 CLS embedding similarity with a cosine threshold of at least 0.985 caught 54 additional semantic near-duplicates. In total, 310 images were discarded — 200 normal and 110 tuberculosis-positive — leaving a curated dataset of 7,698 images: 4,220 normal and 3,478 tuberculosis-positive. Only after this curation was the dataset partitioned, into fixed training, validation, and test sets of 5,389, 1,155, and 1,154 images, split in a class-aware manner to preserve representation across both categories.
Architecturally, TBFuseFormer feeds the same 224-by-224-pixel radiograph into two parallel branches. The Swin Transformer V2 branch processes the image through a stem convolution, stride-four downsampling, and stacked transformer blocks that use local window self-attention, with shifted-window attention across successive stages allowing neighboring windows to exchange information. This produces a hierarchical representation sensitive to fine regional texture and the anatomical location of abnormalities — qualities that matter because tuberculosis can appear as focal opacities, diffuse infiltrates, cavitary changes, pleural abnormalities, or subtle structural alterations. The second branch uses DINOv2 purely as a pretrained feature extractor, not through any student-teacher self-supervised training: the image is divided into patches of size 14, embedded with positional encoding, and passed through the pretrained transformer encoder, whose CLS token yields a compact global feature vector. The two outputs are concatenated and then recalibrated by a channel attention block, which learns to emphasize informative channels and suppress redundant ones before a lightweight fully connected classifier produces probabilities for the two classes.
The comparison was deliberately demanding. Nine architectures — NASNetMobile, DINOv2, ConvNeXt V2, Swin Transformer V2, VGG-16, DenseNet121, MobileNet V3 Large, CoAtNet, and TBFuseFormer — each underwent independent hyperparameter optimization using Optuna with a Tree-structured Parzen Estimator sampler, 24 trials per model, and a search space spanning optimizers, learning rates, weight decay, batch sizes, learning-rate schedules, label smoothing, and fine-tuning strategies. The held-out test set was excluded from all 216 optimization trials, model ranking, threshold adjustment, and configuration selection. This mattered: hyperparameter tuning lifted DenseNet121’s mean cross-validation accuracy by 16.13 percentage points, from 78.49 to 94.62 percent, and produced gains of 8.93, 7.99, 6.61, and 7.87 points for VGG-16, MobileNet V3 Large, NASNetMobile, and CoAtNet-0 respectively. Even so, TBFuseFormer remained on top, with tuned Swin Transformer V2 Base reaching 98.41 plus or minus 0.13 percent, ConvNeXt V2 Base 97.62 plus or minus 0.19 percent, and DINOv2 ViT-B/14 97.36 plus or minus 0.22 percent.
Statistical testing reinforced the ranking. Across fold-wise accuracies for the five strongest models, the Friedman test yielded a chi-square of 19.04 with four degrees of freedom, p equal to 0.0008, and Kendall’s W of 0.952, indicating strong agreement in model ordering across folds. TBFuseFormer ranked first in every fold, with a mean rank of 1.0, and its fold accuracies progressed steadily from 99.26 to 99.64 percent. Pairwise comparisons against tuned baselines remained significant after Holm correction for multiple testing, with mean improvements ranging from 1.10 percentage points over Swin Transformer V2 Base to 4.89 points over DenseNet121, and all 95 percent confidence intervals lying entirely above zero. On the untouched test set of 1,154 images, the model correctly classified 629 of 633 normal cases and 518 of 521 tuberculosis-positive cases, producing only four false positives and three false negatives.
Perhaps the most consequential evaluation was the leave-one-source-out analysis, in which each data source was withheld entirely for testing while the other two formed the development pool. When the Kaggle source was held out, the model evaluated 4,044 unseen images with 96.02 percent accuracy; holding out Mendeley yielded 95.61 percent on 2,896 images, and holding out NIH/IHNCBC gave 94.06 percent on 758 images. Across the three folds, the unweighted mean accuracy was 95.23 percent, with balanced accuracy of 94.36 percent, F1-score of 93.39 percent, Matthews correlation coefficient of 0.864, and AUROC of 0.9836. These figures demonstrate strong generalization to completely unseen sources, though the modest variation across folds indicates that some source-related domain shift — differences in acquisition protocols, preprocessing, and populations — persisted even after deduplication.
The team also interrogated whether the model’s attention actually landed on clinically meaningful regions. Qualitative Grad-CAM visualizations showed that for both normal and tuberculosis-positive samples, the network concentrated on internal thoracic structure rather than image borders or background artifacts. To go beyond visual impressions, the researchers quantified localization faithfulness on a radiologist-annotated subset of 312 tuberculosis-positive test images. TBFuseFormer achieved the highest Pointing Game score of 0.862, energy-based Pointing Game score of 0.532, box IoU of 0.371, box Dice coefficient of 0.469, and insertion AUC of 0.804, while recording the lowest deletion AUC of 0.311 — beating the strongest baseline, Swin Transformer V2 Base, on every metric. Lesion-level analysis revealed that spatially concentrated abnormalities were localized most reliably, with cavitary lesions scoring 0.921 and consolidation 0.884, while miliary or diffuse abnormalities, despite occupying the largest mean proportion of the lung field at 31.6 percent, scored lowest at 0.769.
Practical deployment was addressed through model compression. The full model carries 175.4 million parameters and 33.6 GFLOPs, with batch-one latency of 21.9 milliseconds on an RTX A6000, 74.6 milliseconds on an RTX 3060, 388 milliseconds on a Jetson Orin Nano, and 1,842 milliseconds on a Xeon CPU, all while maintaining the 99.39 percent test accuracy. FP16 inference halved estimated storage from 671 to 336 megabytes without accuracy loss, and INT8 quantization cut storage to 168 megabytes and A6000 latency to 9.1 milliseconds at a small cost of 99.22 percent accuracy. A distilled variant, TBFuse-S, shrinks the model to 50.8 million parameters and 9.2 GFLOPs; its INT8 version reaches 3.6 milliseconds on the A6000 and 41 milliseconds on the Jetson while retaining 98.61 percent accuracy, with throughput rising from 208 to 1,480 images per second on the A6000.
The authors are careful about what these numbers do and do not prove. The study is a retrospective evaluation on a curated multi-source dataset, and the task is strictly binary — real diagnostic practice requires distinguishing tuberculosis from pneumonia, malignancy, chronic lung disease, and other thoracic abnormalities. Deduplication reduces leakage but does not eliminate source-specific heterogeneity, and the reported figures reflect strong internal evaluation rather than confirmed cross-institutional generalization. The Grad-CAM maps should be read as qualitative explanations, with quantitative faithfulness validated only on the annotated tuberculosis-positive subset. Independent multicenter and prospective validation, multiclass testing, and workflow-oriented deployment studies remain necessary before the framework can be considered ready for clinical screening programs — but as a demonstration that rigorous leakage control and strong performance can coexist, the work sets a notably higher bar for how chest X-ray AI should be evaluated.
Subject of Research: A hybrid deep learning framework for leakage-aware binary tuberculosis detection from chest X-ray images
Article Title: Leakage aware tuberculosis detection from chest X-ray images using TBFuseFormer with Swin Transformer V2 and pretrained DINOv2 feature fusion
Article References: Rahim, A., Shehan, M. S. H., Islam, M., Rahman, M. M., Rana, M. S., Islam, M. A., Alam, M. F., Jahan, S., & Raihan, D. I. (2026). Leakage aware tuberculosis detection from chest X-ray images using TBFuseFormer with Swin Transformer V2 and pretrained DINOv2 feature fusion. Discover Analytics, 4(1), Article 43. https://doi.org/10.1007/s44257-026-00092-3
Image Credits: AI Generated
DOI: 10.1007/s44257-026-00092-3
Keywords: tuberculosis, chest X-ray, deep learning, data leakage, Swin Transformer, DINOv2, medical imaging, Grad-CAM, model compression, cross-validation, artificial intelligence, diagnostic screening
Cite Scienmag News
Blake Davidson. (October 28, 2026). AI Model Detects Tuberculosis on Chest X-rays While Guarding Against Data Leakage. Scienmag. https://scienmag.com/ai-model-detects-tuberculosis-on-chest-x-rays-while-guarding-against-data-leakage/
Blake Davidson. "AI Model Detects Tuberculosis on Chest X-rays While Guarding Against Data Leakage." Scienmag, 28 October 2026, https://scienmag.com/ai-model-detects-tuberculosis-on-chest-x-rays-while-guarding-against-data-leakage/. Accessed 28 October 2026.
Blake Davidson. "AI Model Detects Tuberculosis on Chest X-rays While Guarding Against Data Leakage." Scienmag. October 28, 2026. https://scienmag.com/ai-model-detects-tuberculosis-on-chest-x-rays-while-guarding-against-data-leakage/








