Loss-Functions-Package-Tensorflow-Keras-PyTorch icon indicating copy to clipboard operation
Loss-Functions-Package-Tensorflow-Keras-PyTorch copied to clipboard

Multi-Class usage

Open Rekesse opened this issue 3 years ago • 0 comments

Hi, im new to deep learning and python, i have a question: in a multi-class semantic segmentation with 4 classes ( im using keras ) my model has a softmax activation and the input for the model.fit has shape : mask_train[batch, h, w, 4 ]. I can't understand if i have to uncomment these lines or not

def DiceLoss(y_true, y_pred, smooth=1e-6):

# if you are using this loss for multi-class segmentation then uncomment 
# following lines
# if y_pred.shape[-1] <= 1:
#     # activate logits
#     y_pred = tf.keras.activations.sigmoid(y_pred)
# elif y_pred.shape[-1] >= 2:
#     # activate logits
#     y_pred = tf.keras.activations.softmax(y_pred, axis=-1)
#     # convert the tensor to one-hot for multi-class segmentation
#     y_true = K.squeeze(y_true, 3)
#     y_true = tf.cast(y_true, "int32")
#     y_true = tf.one_hot(y_true, num_class, axis=-1)

Rekesse avatar Sep 03 '22 01:09 Rekesse