We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Usage with tf.keras API
https://github.com/tensorflow/addons/blob/5f618fdb92d9737da059de2a33fa606e97505398/tensorflow_addons/losses/focal_loss.py#L52-L53

The usage in `tf.keras` API example is incorrect. It should be replaced with:

```python
model = tf.keras.Model(inputs, outputs)
model.compile('sgd', loss=tfa.losses.SigmoidFocalCrossEntropy())
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tensorflow_addons/losses/focal_loss.py`
Content:
```
1 # Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 # ==============================================================================
15 """Implements Focal loss."""
16 
17 import tensorflow as tf
18 import tensorflow.keras.backend as K
19 
20 from tensorflow_addons.utils.keras_utils import LossFunctionWrapper
21 from tensorflow_addons.utils.types import FloatTensorLike, TensorLike
22 from typeguard import typechecked
23 
24 
25 @tf.keras.utils.register_keras_serializable(package="Addons")
26 class SigmoidFocalCrossEntropy(LossFunctionWrapper):
27     """Implements the focal loss function.
28 
29     Focal loss was first introduced in the RetinaNet paper
30     (https://arxiv.org/pdf/1708.02002.pdf). Focal loss is extremely useful for
31     classification when you have highly imbalanced classes. It down-weights
32     well-classified examples and focuses on hard examples. The loss value is
33     much high for a sample which is misclassified by the classifier as compared
34     to the loss value corresponding to a well-classified example. One of the
35     best use-cases of focal loss is its usage in object detection where the
36     imbalance between the background class and other classes is extremely high.
37 
38     Usage:
39 
40     ```python
41     fl = tfa.losses.SigmoidFocalCrossEntropy()
42     loss = fl(
43       y_true = [[1.0], [1.0], [0.0]],
44       y_pred = [[0.97], [0.91], [0.03]])
45     print('Loss: ', loss.numpy())  # Loss: [6.8532745e-06,
46                                             1.9097870e-04,
47                                             2.0559824e-05]
48     ```
49     Usage with tf.keras API:
50 
51     ```python
52     model = tf.keras.Model(inputs, outputs)
53     model.compile('sgd', loss=tf.keras.losses.SigmoidFocalCrossEntropy())
54     ```
55 
56     Args
57       alpha: balancing factor, default value is 0.25
58       gamma: modulating factor, default value is 2.0
59 
60     Returns:
61       Weighted loss float `Tensor`. If `reduction` is `NONE`, this has the same
62           shape as `y_true`; otherwise, it is scalar.
63 
64     Raises:
65         ValueError: If the shape of `sample_weight` is invalid or value of
66           `gamma` is less than zero
67     """
68 
69     @typechecked
70     def __init__(
71         self,
72         from_logits: bool = False,
73         alpha: FloatTensorLike = 0.25,
74         gamma: FloatTensorLike = 2.0,
75         reduction: str = tf.keras.losses.Reduction.NONE,
76         name: str = "sigmoid_focal_crossentropy",
77     ):
78         super().__init__(
79             sigmoid_focal_crossentropy,
80             name=name,
81             reduction=reduction,
82             from_logits=from_logits,
83             alpha=alpha,
84             gamma=gamma,
85         )
86 
87 
88 @tf.keras.utils.register_keras_serializable(package="Addons")
89 @tf.function
90 def sigmoid_focal_crossentropy(
91     y_true: TensorLike,
92     y_pred: TensorLike,
93     alpha: FloatTensorLike = 0.25,
94     gamma: FloatTensorLike = 2.0,
95     from_logits: bool = False,
96 ) -> tf.Tensor:
97     """
98     Args
99         y_true: true targets tensor.
100         y_pred: predictions tensor.
101         alpha: balancing factor.
102         gamma: modulating factor.
103 
104     Returns:
105         Weighted loss float `Tensor`. If `reduction` is `NONE`,this has the
106         same shape as `y_true`; otherwise, it is scalar.
107     """
108     if gamma and gamma < 0:
109         raise ValueError("Value of gamma should be greater than or equal to zero")
110 
111     y_pred = tf.convert_to_tensor(y_pred)
112     y_true = tf.convert_to_tensor(y_true, dtype=y_pred.dtype)
113 
114     # Get the cross_entropy for each entry
115     ce = K.binary_crossentropy(y_true, y_pred, from_logits=from_logits)
116 
117     # If logits are provided then convert the predictions into probabilities
118     if from_logits:
119         pred_prob = tf.sigmoid(y_pred)
120     else:
121         pred_prob = y_pred
122 
123     p_t = (y_true * pred_prob) + ((1 - y_true) * (1 - pred_prob))
124     alpha_factor = 1.0
125     modulating_factor = 1.0
126 
127     if alpha:
128         alpha = tf.convert_to_tensor(alpha, dtype=K.floatx())
129         alpha_factor = y_true * alpha + (1 - y_true) * (1 - alpha)
130 
131     if gamma:
132         gamma = tf.convert_to_tensor(gamma, dtype=K.floatx())
133         modulating_factor = tf.pow((1.0 - p_t), gamma)
134 
135     # compute the final loss and return
136     return tf.reduce_sum(alpha_factor * modulating_factor * ce, axis=-1)
137
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/tensorflow_addons/losses/focal_loss.py b/tensorflow_addons/losses/focal_loss.py
--- a/tensorflow_addons/losses/focal_loss.py
+++ b/tensorflow_addons/losses/focal_loss.py
@@ -50,7 +50,7 @@
 
     ```python
     model = tf.keras.Model(inputs, outputs)
-    model.compile('sgd', loss=tf.keras.losses.SigmoidFocalCrossEntropy())
+    model.compile('sgd', loss=tfa.losses.SigmoidFocalCrossEntropy())
     ```
 
     Args

{"golden_diff": "diff --git a/tensorflow_addons/losses/focal_loss.py b/tensorflow_addons/losses/focal_loss.py\n--- a/tensorflow_addons/losses/focal_loss.py\n+++ b/tensorflow_addons/losses/focal_loss.py\n@@ -50,7 +50,7 @@\n \n     ```python\n     model = tf.keras.Model(inputs, outputs)\n-    model.compile('sgd', loss=tf.keras.losses.SigmoidFocalCrossEntropy())\n+    model.compile('sgd', loss=tfa.losses.SigmoidFocalCrossEntropy())\n     ```\n \n     Args\n", "issue": "Usage with tf.keras API\nhttps://github.com/tensorflow/addons/blob/5f618fdb92d9737da059de2a33fa606e97505398/tensorflow_addons/losses/focal_loss.py#L52-L53\r\n\r\nThe usage in `tf.keras` API example is incorrect. It should be replaced with:\r\n\r\n```python\r\nmodel = tf.keras.Model(inputs, outputs)\r\nmodel.compile('sgd', loss=tfa.losses.SigmoidFocalCrossEntropy())\r\n```\n", "before_files": [{"content": "# Copyright 2019 The TensorFlow Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"Implements Focal loss.\"\"\"\n\nimport tensorflow as tf\nimport tensorflow.keras.backend as K\n\nfrom tensorflow_addons.utils.keras_utils import LossFunctionWrapper\nfrom tensorflow_addons.utils.types import FloatTensorLike, TensorLike\nfrom typeguard import typechecked\n\n\n@tf.keras.utils.register_keras_serializable(package=\"Addons\")\nclass SigmoidFocalCrossEntropy(LossFunctionWrapper):\n    \"\"\"Implements the focal loss function.\n\n    Focal loss was first introduced in the RetinaNet paper\n    (https://arxiv.org/pdf/1708.02002.pdf). Focal loss is extremely useful for\n    classification when you have highly imbalanced classes. It down-weights\n    well-classified examples and focuses on hard examples. The loss value is\n    much high for a sample which is misclassified by the classifier as compared\n    to the loss value corresponding to a well-classified example. One of the\n    best use-cases of focal loss is its usage in object detection where the\n    imbalance between the background class and other classes is extremely high.\n\n    Usage:\n\n    ```python\n    fl = tfa.losses.SigmoidFocalCrossEntropy()\n    loss = fl(\n      y_true = [[1.0], [1.0], [0.0]],\n      y_pred = [[0.97], [0.91], [0.03]])\n    print('Loss: ', loss.numpy())  # Loss: [6.8532745e-06,\n                                            1.9097870e-04,\n                                            2.0559824e-05]\n    ```\n    Usage with tf.keras API:\n\n    ```python\n    model = tf.keras.Model(inputs, outputs)\n    model.compile('sgd', loss=tf.keras.losses.SigmoidFocalCrossEntropy())\n    ```\n\n    Args\n      alpha: balancing factor, default value is 0.25\n      gamma: modulating factor, default value is 2.0\n\n    Returns:\n      Weighted loss float `Tensor`. If `reduction` is `NONE`, this has the same\n          shape as `y_true`; otherwise, it is scalar.\n\n    Raises:\n        ValueError: If the shape of `sample_weight` is invalid or value of\n          `gamma` is less than zero\n    \"\"\"\n\n    @typechecked\n    def __init__(\n        self,\n        from_logits: bool = False,\n        alpha: FloatTensorLike = 0.25,\n        gamma: FloatTensorLike = 2.0,\n        reduction: str = tf.keras.losses.Reduction.NONE,\n        name: str = \"sigmoid_focal_crossentropy\",\n    ):\n        super().__init__(\n            sigmoid_focal_crossentropy,\n            name=name,\n            reduction=reduction,\n            from_logits=from_logits,\n            alpha=alpha,\n            gamma=gamma,\n        )\n\n\n@tf.keras.utils.register_keras_serializable(package=\"Addons\")\n@tf.function\ndef sigmoid_focal_crossentropy(\n    y_true: TensorLike,\n    y_pred: TensorLike,\n    alpha: FloatTensorLike = 0.25,\n    gamma: FloatTensorLike = 2.0,\n    from_logits: bool = False,\n) -> tf.Tensor:\n    \"\"\"\n    Args\n        y_true: true targets tensor.\n        y_pred: predictions tensor.\n        alpha: balancing factor.\n        gamma: modulating factor.\n\n    Returns:\n        Weighted loss float `Tensor`. If `reduction` is `NONE`,this has the\n        same shape as `y_true`; otherwise, it is scalar.\n    \"\"\"\n    if gamma and gamma < 0:\n        raise ValueError(\"Value of gamma should be greater than or equal to zero\")\n\n    y_pred = tf.convert_to_tensor(y_pred)\n    y_true = tf.convert_to_tensor(y_true, dtype=y_pred.dtype)\n\n    # Get the cross_entropy for each entry\n    ce = K.binary_crossentropy(y_true, y_pred, from_logits=from_logits)\n\n    # If logits are provided then convert the predictions into probabilities\n    if from_logits:\n        pred_prob = tf.sigmoid(y_pred)\n    else:\n        pred_prob = y_pred\n\n    p_t = (y_true * pred_prob) + ((1 - y_true) * (1 - pred_prob))\n    alpha_factor = 1.0\n    modulating_factor = 1.0\n\n    if alpha:\n        alpha = tf.convert_to_tensor(alpha, dtype=K.floatx())\n        alpha_factor = y_true * alpha + (1 - y_true) * (1 - alpha)\n\n    if gamma:\n        gamma = tf.convert_to_tensor(gamma, dtype=K.floatx())\n        modulating_factor = tf.pow((1.0 - p_t), gamma)\n\n    # compute the final loss and return\n    return tf.reduce_sum(alpha_factor * modulating_factor * ce, axis=-1)\n", "path": "tensorflow_addons/losses/focal_loss.py"}], "after_files": [{"content": "# Copyright 2019 The TensorFlow Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n# ==============================================================================\n\"\"\"Implements Focal loss.\"\"\"\n\nimport tensorflow as tf\nimport tensorflow.keras.backend as K\n\nfrom tensorflow_addons.utils.keras_utils import LossFunctionWrapper\nfrom tensorflow_addons.utils.types import FloatTensorLike, TensorLike\nfrom typeguard import typechecked\n\n\n@tf.keras.utils.register_keras_serializable(package=\"Addons\")\nclass SigmoidFocalCrossEntropy(LossFunctionWrapper):\n    \"\"\"Implements the focal loss function.\n\n    Focal loss was first introduced in the RetinaNet paper\n    (https://arxiv.org/pdf/1708.02002.pdf). Focal loss is extremely useful for\n    classification when you have highly imbalanced classes. It down-weights\n    well-classified examples and focuses on hard examples. The loss value is\n    much high for a sample which is misclassified by the classifier as compared\n    to the loss value corresponding to a well-classified example. One of the\n    best use-cases of focal loss is its usage in object detection where the\n    imbalance between the background class and other classes is extremely high.\n\n    Usage:\n\n    ```python\n    fl = tfa.losses.SigmoidFocalCrossEntropy()\n    loss = fl(\n      y_true = [[1.0], [1.0], [0.0]],\n      y_pred = [[0.97], [0.91], [0.03]])\n    print('Loss: ', loss.numpy())  # Loss: [6.8532745e-06,\n                                            1.9097870e-04,\n                                            2.0559824e-05]\n    ```\n    Usage with tf.keras API:\n\n    ```python\n    model = tf.keras.Model(inputs, outputs)\n    model.compile('sgd', loss=tfa.losses.SigmoidFocalCrossEntropy())\n    ```\n\n    Args\n      alpha: balancing factor, default value is 0.25\n      gamma: modulating factor, default value is 2.0\n\n    Returns:\n      Weighted loss float `Tensor`. If `reduction` is `NONE`, this has the same\n          shape as `y_true`; otherwise, it is scalar.\n\n    Raises:\n        ValueError: If the shape of `sample_weight` is invalid or value of\n          `gamma` is less than zero\n    \"\"\"\n\n    @typechecked\n    def __init__(\n        self,\n        from_logits: bool = False,\n        alpha: FloatTensorLike = 0.25,\n        gamma: FloatTensorLike = 2.0,\n        reduction: str = tf.keras.losses.Reduction.NONE,\n        name: str = \"sigmoid_focal_crossentropy\",\n    ):\n        super().__init__(\n            sigmoid_focal_crossentropy,\n            name=name,\n            reduction=reduction,\n            from_logits=from_logits,\n            alpha=alpha,\n            gamma=gamma,\n        )\n\n\n@tf.keras.utils.register_keras_serializable(package=\"Addons\")\n@tf.function\ndef sigmoid_focal_crossentropy(\n    y_true: TensorLike,\n    y_pred: TensorLike,\n    alpha: FloatTensorLike = 0.25,\n    gamma: FloatTensorLike = 2.0,\n    from_logits: bool = False,\n) -> tf.Tensor:\n    \"\"\"\n    Args\n        y_true: true targets tensor.\n        y_pred: predictions tensor.\n        alpha: balancing factor.\n        gamma: modulating factor.\n\n    Returns:\n        Weighted loss float `Tensor`. If `reduction` is `NONE`,this has the\n        same shape as `y_true`; otherwise, it is scalar.\n    \"\"\"\n    if gamma and gamma < 0:\n        raise ValueError(\"Value of gamma should be greater than or equal to zero\")\n\n    y_pred = tf.convert_to_tensor(y_pred)\n    y_true = tf.convert_to_tensor(y_true, dtype=y_pred.dtype)\n\n    # Get the cross_entropy for each entry\n    ce = K.binary_crossentropy(y_true, y_pred, from_logits=from_logits)\n\n    # If logits are provided then convert the predictions into probabilities\n    if from_logits:\n        pred_prob = tf.sigmoid(y_pred)\n    else:\n        pred_prob = y_pred\n\n    p_t = (y_true * pred_prob) + ((1 - y_true) * (1 - pred_prob))\n    alpha_factor = 1.0\n    modulating_factor = 1.0\n\n    if alpha:\n        alpha = tf.convert_to_tensor(alpha, dtype=K.floatx())\n        alpha_factor = y_true * alpha + (1 - y_true) * (1 - alpha)\n\n    if gamma:\n        gamma = tf.convert_to_tensor(gamma, dtype=K.floatx())\n        modulating_factor = tf.pow((1.0 - p_t), gamma)\n\n    # compute the final loss and return\n    return tf.reduce_sum(alpha_factor * modulating_factor * ce, axis=-1)\n", "path": "tensorflow_addons/losses/focal_loss.py"}]}