I am using a in Keras implemented U-Net (https://arxiv.org/pdf/1505.04597.pdf) to segment cell organelles in microscopy images. In order for my network to recognize multiple single objects that are separated by only 1 pixel, I want to use weight maps for each label image (formula is given in publication).
As far as I know, I have to create my own custom loss function (in my case crossentropy) to make use of these weight maps. However, the custom loss function only takes in two parameters. How can I add the weight map values in such a function?
Below is the code for my custom loss function:
def pixelwise_crossentropy(self, ytrue, ypred):
ypred /= tf.reduce_sum(ypred, axis=len(ypred.get_shape()) - 1, keep_dims=True)
# manual computation of crossentropy
_epsilon = tf.convert_to_tensor(epsilon, ypred.dtype.base_dtype)
output = tf.clip_by_value(ypred, _epsilon, 1. - _epsilon)
return - tf.reduce_sum(ytrue * tf.log(output))
Is there any way to combine the weight map values together with the label values in the ytrue tensor?
I apologize if this questions seem stupid, as I said, I'm relatively new to the game. Any help or suggestions would be greatly appreciated!