Scripts and models to run nnUNet inference on CMR images.
First, create a Python environment to install the required packages to run the inference. Here are the steps to create a conda environment, but it should also be possible to use venv. If you need to install conda, I recommend installing Miniconda, which is a lightweight version of Anaconda. You can find steps to install it in this link.
- Create and activate environment (you can call it whatever, here is called cmrnn)
conda create -n cmrnn python=3.12
conda activate cmrnn
- Install PyTorch. Run the command indicated for your system here. In bigblue this command is
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
- Install NNUNet:
python -m pip install nnunetv2
NOTE: the current NNUNet has missing dependencies. You'll need to install them manually using:
python -m pip install blosc2 acvl_utils==0.2
- Clone the CMR-nnUNet repository
git clone https://github.com/javijv4/CMR-nnUNet.git
- Set up paths. This step tells the NNUNet where to find and store the models and data that it needs. Detailed instructions on how to do this can be found here. For a summary, do the following:
a. Create a folder for the NNUNet. This can have any name and be placed wherever you want. The important thing is to save the path.
b. Set up paths:
- In Linux and MacOS: run the following commands in the terminal (temporal solution) or add them to your .bashrc (Linux) or .zshrc (Max).
export nnUNet_raw="path_to_NNUNet_fldr/nnUNet_raw"
export nnUNet_preprocessed="path_to_NNUNet_fldr/nnUNet_preprocessed"
export nnUNet_results="path_to_NNUNet_fldr/nnUNet_results"
- In Windows: follow the steps described for Windows here.
Make sure you downloaded the .zip files to the models folder. DATASET_NAME can be SA, LA_2CH, LA_3CH, LA_4CH.
nnUNetv2_install_pretrained_model_from_zip models/nn_DATASET_NAME.zip
Make sure you have installed the models you want to use (see above).
- Modify the
run.shfile according to the model you need. You need to set themode,id, andnamevariables to one of these combinations
- SA, 41, 3d_fullres
- LA_2CH, 42, 2d
- LA_3CH, 43, 2d
- LA_4CH, 44, 2d
- Run inference (make sure the conda environment is activated!)
bash run.sh
This will create a name_seg.nii.gz containing the segmentation.