Closed innat closed 1 year ago
Okayyy, someone pushed. I think this function should be available here. It's widely used. cc. @gamenerd457
Interested
@LukeWood If you want this please assign it to @gamenerd457 to port his PR here.
@LukeWood @qlzh727 Could u please give some feedback on this and also keras-team/keras-cv#341?
Yea, I think we can host this here (adding this to keras repo might need more extended API review and requirement). We should put this to keras_cv/losses folder.
@gamenerd457 Green light for a PR here.
yeah seems like a great fit!
So should I make a pr here
So should I make a pr here
If the loss easily confirms to the Keras loss API (y_true, y_pred) then yes!
@LukeWood The intention was to port/refactoring @gamenerd457's Addons PR https://github.com/tensorflow/addons/pull/2558/files
@gamenerd457 (cc. @bhack @LukeWood @qlzh727 )
If the loss easily confirms to the Keras loss API (y_true, y_pred) then yes!
Some refactoring may be needed, (i.e. subclassing the tf.keras.losses.Loss
class). I think you can start working on it, either you can move PR from tf-addons or create a new one here. The implementation confirms the keras loss API.
Also please follow the implementation details from segmentation_models/losses.py. This reference implementation offers some useful initial parameter (i.e per_image
, class_weights
etc), which I found very useful in practice.
def dice(y_true, y_pred, ...):
return loss
class Dice(keras.losses.Loss):
def __init__(self,
beta=1,
class_weights=None,
class_indexes=None,
per_image=False, smooth=SMOOTH, name='Dice'):
super().__init__(name=name)
def call(self, y_true, y_pred):
return dice(...)
What are some use cases for per_image?
Also note that in keras we won't support class_weights
; instead, we will support sample_weights
in call.
From HERE.
per_image: If
True
loss is calculated for each image in batch and then averaged, else loss is calculated for the whole batch.
Enabling it to True
provides a performance boost depending on the task.
Cool, we will need to include this in the docstring. Seems like a match!
@DavidLandup0
Here are some info that might be helpful.
per_image
, check 1, check 2, either investigate or consider this comment.
It is one of the most used loss functions in semantic segmentation tasks. Unfortunately still not available in
keras.loss.*
. It has been asked many times, #3611, #13085, #9395, #10890.(Not sure, if it's fit here or
keras.loss.*
)