问题
I'm working in semantic segmentation been inspired from the article of Alex Kendall Segnet I found the Implementation here link, with : Input (rgb) shape=(batch_size, width, height, 3) Output (one-hot) shape=(batch_size, width, height, n_classes)
the number of output classes is 12.
I tried to use The weighted categorical crossentropy loss function since I have my optimal weights vector as below :
def weighted_categorical_crossentropy(weights):
# weights = [0.9,0.05,0.04,0.01]
def wcce(y_true, y_pred):
Kweights = K.constant(weights)
if not K.is_tensor(y_pred): y_pred = K.constant(y_pred)
y_true = K.cast(y_true, y_pred.dtype)
return K.categorical_crossentropy(y_true, y_pred) * K.sum(y_true * Kweights, axis=-1)
return wcce
it worked for me I'm getting no error but the result of loss and accuracy is the same. is it the right way to use weighted_categorical_crossentopy.
来源:https://stackoverflow.com/questions/61309991/how-to-use-weighted-categorical-crossentropy-loss-function