Downloads · 30 days
0
M20VJ/tb_classification_files
tb_classification_files is a machine learning model from M20VJ. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repo provides a turnkey PyTorch/Transformers pipeline for finetuning facebook/dinov3-convnext-large-pretrain-lvd1689m on chest X-ray DICOM files from indiantbxrayscandataset. The script automates clinically-motiv…
Downloads · 30 days
0
Access
Public
Updated Nov 14, 2025
Repo size
1.3 GB
Likes
0
Public
Click a slice to open those files.
.pt1.3 GB · 100%
From the Hugging Face model README
This repo provides a turnkey PyTorch/Transformers pipeline for finetuning facebook/dinov3-convnext-large-pretrain-lvd1689m on chest X-ray DICOM files from indian_tb_xray_scan_dataset. The script automates clinically-motivated best practices: advanced augmentations (MixUp, CutMix, CLAHE, Gaussian noise), focal loss + class weighting, SMOTE-Tomek rebalancing, shortcut auditing, domain adversarial regularization, temperature scaling, MC-dropout uncertainty, TTA, and ensemble evaluation.
pip install -r requirements.txt
Place DICOM studies under indian_tb_xray_scan_dataset using the provided folder split:
indian_tb_xray_scan_dataset/
abnormal-tuberculosis/
*.dicom|*.dcm
normal/
*.dicom|*.dcm
Optionally provide metadata.csv with filepath,domain columns to expose acquisition-site domains for adversarial alignment.
python train_tb_classifier.py \
--data_root indian_tb_xray_scan_dataset \
--output_dir runs/baseline \
--batch_size 8 \
--epochs 10 \
--amp
Key switches:
--mixup_alpha/--cutmix_alpha: enable MixUp/CutMix (set to 0 to disable).--smote_tomek: rebalance training split using SMOTE-Tomek on radiograph statistics.--audit_shortcuts: dump shortcut_report.json with contrast/brightness deltas per label.--use_weighted_sampler --class_weights 1.0 2.0: increase recall on TB-positive cases.--tta and --mc_dropout_samples 16: activate test-time augmentation + Monte-Carlo dropout metrics.python train_tb_classifier.py \
--num_models 3 \
--seed 7 \
--output_dir runs/ensemble \
--tta --mc_dropout_samples 16
Each seed trains independently, calibrates via temperature scaling, and the script reports both per-model and ensemble metrics.
Prefer the Hugging Face timm MaxViT checkpoint timm/maxvit_base_tf_512.in21k_ft_in1k? Use the companion script:
python train_tb_classifier_maxvit.py \
--data_root indian_tb_xray_scan_dataset \
--output_dir runs/maxvit \
--batch_size 4 \
--epochs 10 \
--amp
It mirrors the Dinov3 pipeline (CLAHE, MixUp/CutMix, focal loss, SMOTE-Tomek, calibration, MC-dropout/TTA) but defaults to 512×512 inputs and pulls normalization metadata from the timm data_config.
python train_tb_classifier.py \
--eval_only \
--checkpoint runs/baseline/tb_dinov3_run0.pt \
--tta --mc_dropout_samples 16
Pass extra checkpoints via --ensemble_checkpoints ckpt1.pt ckpt2.pt to fuse heterogeneous backbones.
Once training finishes, run calibrated inference with the dedicated helper (automatically mirrors CLAHE, normalization, and optional TTA/MC dropout):
python inference_tb_classifier.py \
--checkpoint runs/baseline/tb_dinov3_run0.pt \
--temperature_path runs/baseline/temperature_run1.pt \
--data_root indian_tb_xray_scan_dataset \
--output_dir runs/baseline/inference \
--batch_size 64 \
--amp --tta
Set --mc_dropout_samples 8 to retrieve epistemic uncertainty estimates, and add --save_predictions --save_logits to dump CSV/tensor artifacts for downstream audit.
metrics.json: full validation/test stats (accuracy, F1, AUC, ECE, MC-dropout uncertainty, etc.).temperature_run*.pt: calibrated temperature parameters per model.history_run*.json: per-epoch logs.logits.pt (set --save_logits).AutoModel loads Dinov3 ConvNeXt; AutoTokenizer is initialized for completeness even though this is a vision backbone.Run python train_tb_classifier.py --help to inspect every flag.