categorical_focal_gain: Function for categorical focal gain

View source: R/customMetrics.R

categorical_focal_gainR Documentation

Function for categorical focal gain

Description

The negative of the categorical focal loss discussed in this paper:

Usage

categorical_focal_gain(y_true, y_pred, gamma = 2, alpha = 0.25)

Arguments

y_true

True labels (Tensor)

y_pred

Predictions (Tensor of the same shape as y_true)

gamma

focusing parameter for modulating factor (1-p). Default = 2.0.

alpha

weighing factor in balanced cross entropy. Default = 0.25.

Details

https://arxiv.org/pdf/1708.02002.pdf

and ported from this implementation:

https://github.com/umbertogriffo/focal-loss-keras/blob/master/losses.py

Used to handle imbalanced classes.

Value

function value

Author(s)

Tustison NJ

Examples


library( ANTsRNet )
library( keras )

model <- createUnetModel2D( c( 64, 64, 1 ) )

metric_categorical_focal_gain <-
  custom_metric( "categorical_focal_gain",
    categorical_focal_gain( alpha = 0.25, gamma = 2.0 ) )

model %>% compile( loss = categorical_focal_loss( alpha = 0.25, gamma = 2.0 ),
 optimizer = optimizer_adam( lr = 0.0001 ),
   metrics = c( metric_categorical_focal_gain ) )


ANTsX/ANTsRNet documentation built on April 23, 2024, 1:24 p.m.