/PHANES

Reversing the Abnormal: Pseudo-Healthy Generative Networks for Anomaly Detection

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

The code is being tested...


Reversing the Abnormal: Pseudo-Healthy Generative Networks for Anomaly Detection

Cosmin BerceaBenedikt WiestlerDaniel Rueckert Julia A. Schnabel

Official repository of the paper

MICCAI 2023

Citation

If you find our work helpful, please cite our paper:

@article{bercea2023reversing,
  title={Reversing the abnormal: Pseudo-healthy generative networks for anomaly detection},
  author={Bercea, Cosmin I and Wiestler, Benedikt and Rueckert, Daniel and Schnabel, Julia A},
  journal={arXiv preprint arXiv:2303.08452},
  year={2023}
}

Abstract: Early and accurate disease detection is crucial for patient management and successful treatment outcomes. However, the automatic identification of anomalies in medical images can be challenging. Conventional methods rely on large labeled datasets which are difficult to obtain. To overcome these limitations, we introduce a novel unsupervised approach, called PHANES (Pseudo Healthy generative networks for ANomaly Segmentation). Our method has the capability of reversing anomalies, i.e., preserving healthy tissue and replacing anomalous regions with pseudo-healthy (PH) reconstructions. Unlike recent diffusion models, our method does not rely on a learned noise distribution nor does it introduce random alterations to the entire image. Instead, we use latent generative networks to create masks around possible anomalies, which are refined using inpainting generative networks. We demonstrate the effectiveness of PHANES in detecting stroke lesions in T1w brain MRI datasets and show significant improvements over state-of-the-art (SOTA) methods. We believe that our proposed framework will open new avenues for interpretable, fast, and accurate anomaly segmentation with the potential to support various clinical-oriented downstream tasks.

Setup and Run

The code is based on the deep learning framework from the Institute of Machine Learning in Biomedical Imaging: https://github.com/compai-lab/iml-dl

Framework Overview:

Sign up for a free account and login to your wandb account.

wandb login

Paste the API key from https://wandb.ai/authorize when prompted.

2). Clone repository

git clone https://github.com/ci-ber/PHANES.git
cd PHANES

3). Install requirements

pip install -r pip_requirements.txt

or conda:

conda create --name phanes_py308 --file conda_requirements.txt
conda activate phanes_py308

4). Install PyTorch

Example installation:

  • with cuda:
pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html
  • w/o cuda:
pip3 install torch==1.9.1 torchvision==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html

5). Download datasets

Alternatively you can use your own mid-axial slices of T1w brain scans with our pre-trained weights or train from scratch on other anatomies and modalities.

6). !!! Set the right threshold

You have to choose a threshold for binarizing the probable anomaly masks of the first step. Be mindful of this step since it can dramatically influence the outcome. In the paper, we use a threshold that delivers at most 5% false positive for inference masking_threshold_infer: 0.153 in the phanes.yaml config file (0.153 for the given dataset). We choose a lower threshold for training (masking_threshold_train: 0.1) since the networks make fewer errors on the training data and we need to train the GAN with some input. This has to be set for each dataset individually since the network might produce different errors on healthy data due to domain shifts! You can use the thresholding function in the DownStreamEvaluator.py to compute these on a healthy subsample of that distribution or use None otherwise (This will automatically filter the 95% percentile of each scan individually).

7). Run the pipeline

Run the main script with the corresponding config like this:

python core/Main.py --config_path ./projects/phanes/phanes.yaml

Refer to phanes.yaml for the default configuration.

That's it, enjoy! 🚀