nicolov / segmentation_keras

DilatedNet in Keras for image segmentation
MIT License
301 stars 92 forks source link

Why sparse_categorical_crossentropy is used? #42

Closed mrgloom closed 6 years ago

mrgloom commented 6 years ago

Why sparse_categorical_crossentropy is used?

Looks like here is softmax is used: https://github.com/nicolov/segmentation_keras/blob/master/model.py#L60

Also I don't understand why our mask batch is: mask_batch = np.zeros((batch_size, mask_target_size[0] * mask_target_size[1], 1) and not mask_batch = np.zeros((batch_size, mask_target_size[0] * mask_target_size[1], 21) ? https://github.com/nicolov/segmentation_keras/blob/master/utils/image_reader.py#L194

nicolov commented 6 years ago

sparse_categorical_crossentropy does the 1-hot encoding internally. This is also the reason why the mask is 1-dimensional, rather than 21-dimensional (where 21 is the number of classes).