aurora95 / Keras-FCN

Keras-tensorflow implementation of Fully Convolutional Networks for Semantic Segmentation(Unfinished)
MIT License
650 stars 268 forks source link

Loss function modification #44

Open groot-1313 opened 7 years ago

groot-1313 commented 7 years ago

I have 300x300 single channel images. I am trying a segmentation problem. I have two classes - object1 and object2, and the rest is background. Therefore, my output is of size 300x300x2. 1st channel has 0s representing background and object2, and 1s representing object1. 2nd channel has 0s representing background and object1, and 1s representing object2. What changes are required in the "softmax_sparse_crossentropy_ignoring_last_label" function in order for me to be able to use it, because your loss function involves finding the one hot vector from the output obtained, and I believe my output is already in that form. Is this part of the code required for my application?

y_true = K.one_hot(tf.to_int32(K.flatten(y_true)), K.int_shape(y_pred)[-1]+1)

unpacked = tf.unstack(y_true, axis=-1)

y_true = tf.stack(unpacked[:-1], axis=-1)
mrgloom commented 6 years ago

I think in case of softmax+categorical_crossentropy you need 3 planes [object1,object2,background] in case of sigmoid+binary_crossentropy 2 planes [object1,object2].