Open Halleyawoo opened 2 days ago
Also, could you please let me know what version of the virtual environment I need to install? Is it the same as the one for nnUNet V2? Additionally, should I install the libraries mentioned in your README, such as:
pip install monai
pip install cucim-cu12 pip install cupy==12.3
pip install cucim-cu11 pip install cupy-cuda11x
Hello, thank you for your questions!
Regarding your question, there are two ways to implement the cbDice
loss in your project.
Option 1: Using the nnUNet Framework
If you are using the nnUNet framework, you can integrate the cbDice
loss directly by copying the loss
code to the nnUNet-2.2/nnunetv2/training/loss/
directory. Additionally, move the nnUNetTrainer_variants
code to the nnUNet-2.2/nnunetv2/training/nnUNetTrainer/
directory. After setting this up, you will need to install the nnUNet environment, along with monai
, cucim
, and cupy
.
Option 2: Without the nnUNet Framework
Alternatively, if you aren’t using the nnUNet framework, you can integrate cbDice_loss.py
and compound_cbdice_loss.py
directly into your training code. Check out the example code on GitHub (nnUNetTrainer_CE_DC_CBDC.py#L25) for further details on parameter setup. For instance, you can configure the loss
as follows:
loss = DC_and_CE_and_CBDC_loss(
{'batch_dice': True, 'smooth': 1e-5, 'do_bg': False, 'ddp': False},
{},
{'iter_': 10, 'smooth': 1e-3},
weight_ce=lambda_ce, weight_dice=lambda_dice, weight_cbdice=lambda_cbdice,
ignore_label=None, dice_class=MemoryEfficientSoftDiceLoss
)
In this setup, you only need a few packages such as torch
, monai
, cucim
, and cupy
.
The skeleton information is automatically extracted during training when using cbDice
loss. You can refer to the specific extraction steps in the cbDice loss code or the clDice
loss code if you're using that variant.
The required libraries and installation steps are as follows:
Install monai
:
pip install monai
For CUDA 12.x:
pip install cucim-cu12
pip install cupy==12.3
For CUDA 11.x:
pip install cucim-cu11
pip install cupy-cuda11x
These libraries support GPU-accelerated operations, like the distance transform, which cbDice
loss uses for efficient training (link).
Thank you once again, and feel free to reach out with any additional questions.
@PengchengShi1220 Thank you for your very detailed answers; they are incredibly helpful. I appreciate it!
Thank you for your valuable work. I noticed that the code you uploaded on GitHub is the core module. I would like to ask if I should download the code you provided and place it within the nnUNet framework for training and testing, correct? Additionally, is the skeleton information extracted from the original data and then incorporated into the nnUNet data format, or is the skeleton information automatically extracted during training?
Thanks again and I looking forward your reply.