Skip to content

Instantly share code, notes, and snippets.

View boriswinner's full-sized avatar

Boris Timofeenko boriswinner

  • St. Petersburg
View GitHub Profile
@wassname
wassname / keras_weighted_categorical_crossentropy.py
Last active October 10, 2024 00:52
Keras weighted categorical_crossentropy (please read comments for updated version)
"""
A weighted version of categorical_crossentropy for keras (2.0.6). This lets you apply a weight to unbalanced classes.
@url: https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d
@author: wassname
"""
from keras import backend as K
def weighted_categorical_crossentropy(weights):
"""
A weighted version of keras.objectives.categorical_crossentropy