This repository contains the implementation of the paper Anomaly Detection in Thoracic CT - A Public Benchmark based on CT-RATE published at BVM 2026.
The implementation was done in Python 3.12. The required packages and versions are listed in requirements.txt.
In the paper, the dataset CT-RATE-AD for anomaly detection in thoracic CT is curated based on the public dataset CT-RATE. CT-RATE-AD consists of:
- training set of 3565 healthy samples (listed in
data/data_csv/train_healthy.csv) - validation set of 500 healthy samples (listed in
data/data_csv/valid_healthy.csv) - test set of 500 healthy and 500 unhealthy samples (listed in
data/data_csv/test_healthy.csvanddata/data_csv/test_unhealthy.csv)
Download the samples from CT-RATE and put them into data/dataset/ distributed in the subdirectories train/healthy, valid/healthy, test/healthy, and test/unhealthy.
Then resample the data to 0.75 mm spacing in data/resample.py. The resampled scans will be stored in data/preprocessed_dataset.
To establish a baseline on CT-RATE-AD, various anomaly detection methods are evaluated in the paper. The following results were obtained:
| Method | AUROC | AP | Specificity @ 95% Sensitivity |
|---|---|---|---|
| Voxel Intensity | 0.5830 | 0.5672 | 0.0714 |
| CT-FM | 0.5707 | 0.5871 | 0.0500 |
| 2D VAE | 0.6463 | 0.6212 | 0.1567 |
| 3D VAE | 0.6455 | 0.6138 | 0.1486 |
| CP + nnU-Net 2d | 0.5389 | 0.5410 | 0.0000 |
| CP + nnU-Net 3d_lr | 0.5315 | 0.5100 | 0.0653 |
| CP + nnU-Net 3d_fr | 0.5623 | 0.5266 | 0.1586 |
The voxel-intensity-based methods can be run with methods/voxel_intensity.py. The resulting AUROC, AP, and specificity at 95% sensitivity are printed to the terminal.
- Compute the CT-FM embeddings of the volumes with
methods/ct-fm/compute_embeddings.py. The resulting embeddings are stored as pkl files inmethods/ct-fm/embeddings. - Fit a GMM on the embeddings with
methods/ct-fm/fit_GMM.py. The resulting GMM is stored asmethods/ct-fm/gmm.joblib. - Get the metrics of this method with
methods/ct-fm/evaluate.py.
- Train the VAE with
methods/vae/train.pyspecifying the dimensionality (2 or 3) via the command line parameter--spatial_dims. The trained model is saved asvae2d_best_val_30.pthorvae3d_best_val_30.pth. - Get the metrics of this method with
methods/vae/evaluate.pyspecifying the dimensionality via--spatial_dims. - The reconstruction of a specific volume can be obtained with
methods/vae/inference.pyspecifying the dimensionality via--spatial_dimsand the path to the volume via--vol_path. The reconstructed volume is saved inmethods/vae/recon_2dormethods/vae/recon_3d.
- Insert synthetic anomalies into the training and validation volumes with
methods/cp/insert_anomalies.py. The modified volumes are stored inmethods/cp/nnUNet/nnUNet_raw/Dataset001_CT-RATE_CP/imagesTrand the binary masks of the inserted anomalies inmethods/cp/nnUNet/nnUNet_raw/Dataset001_CT-RATE_CP/labelsTr. - Train an nnU-Net on the segmentation of the synthetic anomalies.
- Set the environment variables:
export nnUNet_raw="methods/cp/nnUNet/nnUNet_raw" export nnUNet_preprocessed="/methods/cp/nnUNet/nnUNet_preprocessed" export nnUNet_results="/methods/cp/nnUNet/nnUNet/nnUNet_results" - Run the planning and preprocessing with
nnUNetv2_plan_and_preprocess -d 1. - Train the different configurations of the nnU-Net with
nnUNetv2_train 1 UNET_CONFIGURATION FOLD --npzwithUNET_CONFIGURATIONin {2d,3d_fullres,3d_lowres}FOLDin {0, ..., 4} for each configuration
- Copy the healthy and unhealthy test samples into
nnUNet/nnUNet_raw/Dataset001_CT-RATE_CP/imagesTsand insert_0000before.nii.gzinto the file names. - Get the inference and postprocessing commands for each configuration with
nnUNetv2_find_best_configuration 1 -c UNET_CONFIGURATIONwithUNET_CONFIGURATIONin {2d,3d_fullres,3d_lowres}. - Execute the obtained inference and postprocessing instructions for each configuration specifying
nnUNet/nnUNet_raw/Dataset001_CT-RATE_CP/imagesTsas input directory and/nnUNet/nnUNet_results/Dataset001_CT-RATE_CP/nnUNetTrainer__nnUNetPlans__{CONF}/test_resultswithCONFin {2d,3d_fullres,3d_lowres} as output directory.
- Set the environment variables:
- Get the metrics of this method with
methods/cp/evaluate.py.
In case of any questions, please contact me at franziska.fw.weber@fau.de.