This repository provides a maintained implementation aimed at reproducing the results of the paper "SwinCheX: Multi-label classification on chest X-ray images with transformer".
The codebase was adapted to run efficiently on the Heisenberg HPC cluster at Ilum – School of Science, as part of the activities developed during the Winter Internship at the Brazilian Synchrotron Light Laboratory (LNLS) within the Data Science Group (GCD).
The original implementation was modified primarily to ensure compatibility with the HPC environment and modern GPU software stacks. The key changes include:
- Adoption of native PyTorch Automatic Mixed Precision (AMP), replacing NVIDIA Apex, which is unavailable under CUDA 12.1
- Upgrade of core dependencies to the most recent versions mutually compatible with each other and with CUDA 12.1
Instructions for environment setup and pretrained model preparation are provided in
get_started.md.
In this reproduction, we use the ImageNet-22K pretrained Swin-T model, configured with an input resolution of 224×224, as the backbone for training.
All required Python libraries are listed in requirements.txt.
To install them, run:
pip install -r requirements.txtDownload the NIH ChestX-ray14 Dataset from Kaggle.
After downloading, merge the images from the provided subfolders into a single directory. Optionally, you may organize separate folders for training, validation, and testing.
To launch training on a single GPU, execute:
python -m torch.distributed.launch --nproc_per_node 1 --master_port 12345 main.py \
--local_rank 0 \
--cfg configs/swin_tiny_patch4_window7_224.yaml \
--resume swin_tiny_patch4_window7_224.pth \
--trainset path/to/trainset/images \
--validset path/to/validset/images \
--testset path/to/testset/images \
--train_csv_path configs/NIH/train.csv \
--valid_csv_path configs/NIH/validation.csv \
--test_csv_path configs/NIH/test.csv \
--batch-size 4 \
--accumulation-steps 4The Swin-T-based model was trained for 300 epochs, demonstrating strong generalization performance across both validation and test sets.
- Average training time per epoch: 23.66 min
The model achieved high discriminative capability during validation:
| Metric | Value |
|---|---|
| Mean AUC | 0.75440 |
| Accuracy | 95.57% |
| Loss | 0.16972 |
On the held-out test set, the model maintained competitive performance:
| Metric | Value |
|---|---|
| Mean AUC | 0.72008 |
| Accuracy | 92.45% |
| Loss | 0.23426 |
To assess the generalization capability of the trained model, inference was performed on the validation split of the CheXpert dataset, which was not used during training. The model achieved the following performance metrics:
| Metric | Value |
|---|---|
| Mean AUC | 0.72530 |
| Accuracy | 81.26% |
-
If all images are stored in a single directory, then the
--trainset,--validset, and--testsetarguments should all point to the same folder. -
To resume training from an intermediate checkpoint, you must comment out the line marked with "TODO" inside
utils.py.