View source: R/customMetrics.R
multilabel_dice_coefficient | R Documentation |
Note: Assumption is that y_true is a one-hot representation of the segmentation batch. The background (label 0) should be included but is not used in the calculation.
multilabel_dice_coefficient(
y_true,
y_pred,
dimensionality = 3L,
smoothingFactor = 0
)
y_true |
True labels (Tensor) |
y_pred |
Predictions (Tensor of the same shape as |
dimensionality |
image dimension. |
smoothingFactor |
parameter for smoothing the metric. |
Dice value (negative)
Tustison NJ
library( ANTsR )
library( ANTsRNet )
library( keras )
model <- createUnetModel2D( c( 64, 64, 1 ) )
dice_loss <- multilabel_dice_coefficient( smoothingFactor = 0.1 )
model %>% compile( loss = dice_loss,
optimizer = optimizer_adam( lr = 0.0001 ) )
########################################
#
# Run in isolation
#
library( ANTsR )
r16 <- antsImageRead( getANTsRData( "r16" ) )
r16seg <- kmeansSegmentation( r16, 3 )$segmentation
r16array <- array( data = as.array( r16seg ), dim = c( 1, dim( r16seg ) ) )
r16tensor <- tensorflow::tf$convert_to_tensor( encodeUnet( r16array, c( 0, 1, 2, 3 ) ) )
r64 <- antsImageRead( getANTsRData( "r64" ) )
r64seg <- kmeansSegmentation( r64, 3 )$segmentation
r64array <- array( data = as.array( r64seg ), dim = c( 1, dim( r64seg ) ) )
r64tensor <- tensorflow::tf$convert_to_tensor( encodeUnet( r64array, c( 0, 1, 2, 3 ) ) )
dice_loss <- multilabel_dice_coefficient( r16tensor, r64tensor, dimensionality = 2L )
loss_value <- dice_loss( r16tensor, r64tensor )$numpy()
# Compare with
# overlap_value <- labelOverlapMeasures( r16seg, r64seg )$MeanOverlap[1]
rm(model); gc()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.