ported from this implementation:

weighted_categorical_crossentropy(y_true, y_pred, weights)

Arguments

y_true

True labels (Tensor)

y_pred

Predictions (Tensor of the same shape as y_true)

weights

weights for each class

Value

function value

Details

https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d

Author

Tustison NJ

Examples

library( ANTsRNet ) library( keras ) model <- createUnetModel2D( c( 64, 64, 1 ), numberOfOutputs = 2 )
#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not exist
model %>% compile( loss = weighted_categorical_crossentropy( weights = c( 1, 1 ) ), optimizer = optimizer_adam( lr = 0.0001 ), metrics = "accuracy" )
#> Error in compile(., loss = weighted_categorical_crossentropy(weights = c(1, 1)), optimizer = optimizer_adam(lr = 1e-04), metrics = "accuracy"): object 'model' not found