Created
July 22, 2021 05:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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