add_custom_loss
code_loader.leap_binder.add_custom_loss
code_loader.leap_binder.add_custom_loss(
function=CustomCallableInterface,
name=str
)Args
Examples
Basic Usage
import numpy as np
from code_loader import leap_binder
...
def weighted_categorical_crossentropy(y_true, y_pred):
# scale predictions so that the class probas of each sample sum to 1
y_pred /= K.sum(y_pred, axis=-1, keepdims=True)
# clip to prevent NaN's and Inf's
y_pred = K.clip(y_pred, K.epsilon(), 1 - K.epsilon())
# calc
weights = np.array([0.5, 2.1, 3, 4, 4, 4, 4, 4])
loss = y_true * K.log(y_pred) * weights
loss = -K.sum(loss, -1)
return loss
...
leap_binder.add_custom_loss(
function=weighted_categorical_crossentropy,
name='weighted_categorical_crossentropy'
)Last updated
Was this helpful?

