How do I create a custom Dice pixel classification layer in MATLAB R2022a using the Computer Vision Toolbox?

4 views (last 30 days)
I am using the information on the "3-D Brain Tumor Segmentation Using Deep Learning" tutorial page to carry out training on three-dimensional scans in images:
However, I am having difficulty in implementing a custom Dice layer in MATLAB R2022a using this tutorial page above as guidance.
Are there any other resources that would help me to implement a custom Dice layer?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Oct 2025 at 0:00
Edited: MathWorks Support Team on 10 Oct 2025 at 10:30
For a detailed MATLAB implementation on building a custom Dice layer, please refer to the "Define Custom Pixel Classification Layer with Tversky Loss" documentation page:
The Tversky Loss differs from the Dice Loss by having different weights for false positives (FPs) and false negatives (FNs) in the loss function, unlike the Dice Loss which weights both FPs and FNs equally. Given the default settings in the example code in the Tversky Loss documentation page linked above, alpha=0.5 and beta=0.5, this will simplify to the Dice score. For further reference on the Tversky Loss, please consult Section 2.2 of the following publication:

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!