Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealnaveenkamal/b1ddebb0f44ad84e393e0d03bbabbd40 to your computer and use it in GitHub Desktop.
Save therealnaveenkamal/b1ddebb0f44ad84e393e0d03bbabbd40 to your computer and use it in GitHub Desktop.
This is a customized loss function for Chest X-Ray Multi-class classification problem addressing the class imbalance issue
def calcloss(positivewt, negativewt, al=1e-7):
def weighted_loss(y_true, y_pred):
loss = 0.0
for i in range(len(positivewt)):
loss += -((positivewt[i] * K.transpose(y_true)[i] * K.log(K.transpose(y_pred)[i] + al))+(negativewt[i]*(1 - K.transpose(y_true)[i])*K.log(1 - K.transpose(y_pred)[i] + al)))
return K.mean(loss)
return weighted_loss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment