R/customMetrics.R
multilabel_dice_coefficient.Rd
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
#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not existdice_loss <- multilabel_dice_coefficient( smoothingFactor = 0.1 ) model %>% compile( loss = dice_loss, optimizer = optimizer_adam( lr = 0.0001 ) )#> Error in compile(., loss = dice_loss, optimizer = optimizer_adam(lr = 1e-04)): object 'model' not found######################################## # # 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 ) ) )#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not existr64 <- 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 ) ) )#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not existdice_loss <- multilabel_dice_coefficient( r16tensor, r64tensor, dimensionality = 2L ) loss_value <- dice_loss( r16tensor, r64tensor )$numpy()#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not exist# Compare with # overlap_value <- labelOverlapMeasures( r16seg, r64seg )$MeanOverlap[1] rm(model); gc()#> Warning: object 'model' not found#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 2560923 136.8 4570014 244.1 NA 4570014 244.1 #> Vcells 4660055 35.6 12255594 93.6 65536 12254504 93.5