You can also not do reshape
anything and determine both softmax
, and loss
yourself. Here softmax
, which applies to the last input size (e.g. in the tf
backend):
def image_softmax(input):
label_dim = -1
d = K.exp(input - K.max(input, axis=label_dim, keepdims=True))
return d / K.sum(d, axis=label_dim, keepdims=True)
and here you have it loss
(no need to rename anything):
__EPS = 1e-5
def image_categorical_crossentropy(y_true, y_pred):
y_pred = K.clip(y_pred, __EPS, 1 - __EPS)
return -K.mean(y_true * K.log(y_pred) + (1 - y_true) * K.log(1 - y_pred))
No further changes are required.
source
share