MCPcopy Create free account
hub / github.com/tensorflow/models / build_losses

Method build_losses

official/core/base_task.py:169–187  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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."""

Callers 2

train_stepMethod · 0.95
validation_stepMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected