qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.7k stars 1.03k forks source link

problem in categorical_focal_loss #309

Open LeeJayHui opened 4 years ago

LeeJayHui commented 4 years ago

Hi, I think there is probably a mistake in here: https://github.com/qubvel/segmentation_models/blob/a6fbf2d5ea21081929df634d095d389211e649ef/segmentation_models/base/functional.py#L281. The values in gt array here are either one or zero. The above implementation would just simply ignore the zero ground truth when calculating the focal loss. I think maybe it should be written as follow (alpha does nothing here) :

sumanttyagi commented 3 years ago

i have one doubt , i am getting error for using hot encoding for multi class classification 541 str_values = [compat.as_bytes(x) for x in proto_values] 542 except TypeError:

15 frames TypeError: Expected binary or unicode string, got <segmentation_models.losses.CategoricalFocalLoss object at 0x7f35ff920f10>

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) /tensorflow-1.15.2/python3.7/tensorflow_core/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape, allow_broadcast) 543 raise TypeError("Failed to convert object of type %s to Tensor. " 544 "Contents: %s. Consider casting elements to a " --> 545 "supported type." % (type(values), values)) 546 tensor_proto.string_val.extend(str_values) 547 return tensor_proto

TypeError: Failed to convert object of type <class 'segmentation_models.losses.CategoricalFocalLoss'> to Tensor. Contents: <segmentation_models.losses.CategoricalFocalLoss object at 0x7f35ff920f10>. Consider casting elements to a supported type.