Standard interface to compute losses. Args: labels: optional label tensors. model_outputs: a nested structure of output tensors. aux_losses: auxiliary loss tensors, i.e. `losses` in keras.Model. Returns: The total loss tensor.
(self, labels, model_outputs, aux_losses=None)
| 167 | """ |
| 168 | |
| 169 | def build_losses(self, labels, model_outputs, aux_losses=None) -> tf.Tensor: |
| 170 | """Standard interface to compute losses. |
| 171 | |
| 172 | Args: |
| 173 | labels: optional label tensors. |
| 174 | model_outputs: a nested structure of output tensors. |
| 175 | aux_losses: auxiliary loss tensors, i.e. `losses` in keras.Model. |
| 176 | |
| 177 | Returns: |
| 178 | The total loss tensor. |
| 179 | """ |
| 180 | del model_outputs, labels |
| 181 | |
| 182 | if aux_losses is None: |
| 183 | losses = [tf.constant(0.0, dtype=tf.float32)] |
| 184 | else: |
| 185 | losses = aux_losses |
| 186 | total_loss = tf.add_n(losses) |
| 187 | return total_loss |
| 188 | |
| 189 | def build_metrics(self, training: bool = True): |
| 190 | """Gets streaming metrics for training/validation.""" |
no outgoing calls
no test coverage detected