custom keras loss function for counting non zero or one values

痴心易碎 提交于 2019-12-24 10:24:37

问题


I have a cost function in Keras which has 3 parts related to the different output of my network. suppose this is my loss function:

aL1+bL2+cL3 that L1 is mse, L2 is binary cross-entropy and L3 try to make minimum the number of pixels in the output that does not have value 0 or 1(∑n (x≠0 or x≠1)), but I do not know how can I make the last loss function?!( a,b and c are coefficients for each loss functions)

The output should be a 28x28 binary image which values are 0 or 1. by adding this term to loss function I try to force the output to be 0 or 1 and other values try to put in one of these two class. but I do not know how can I produce this loss function or I have the combination of these loss functions? if I only have two first loss function I do this

model.compile(optimizer=opt, loss=`{'decoder_output':'mse','reconstructed_W':'binary_crossentropy'}, loss_weights={'decoder_output': 0.1, 'reconstructed_W': 1.0},metrics=['mae'])` 

the third loss is related to reconstructed_w and I want to force its value to be only 0 or 1 but I do not know how to code this. could you please help me with this issue? I appreciate your help. I really need your guidance.

来源:https://stackoverflow.com/questions/55147714/custom-keras-loss-function-for-counting-non-zero-or-one-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!