Validation step. With distribution strategies, this method runs on devices. Args: inputs: a dictionary of input tensors. model: the keras.Model. metrics: a nested structure of metrics objects. Returns: A dictionary of logs.
(self, inputs, model: tf_keras.Model, metrics=None)
| 280 | return logs |
| 281 | |
| 282 | def validation_step(self, inputs, model: tf_keras.Model, metrics=None): |
| 283 | """Validation step. |
| 284 | |
| 285 | With distribution strategies, this method runs on devices. |
| 286 | |
| 287 | Args: |
| 288 | inputs: a dictionary of input tensors. |
| 289 | model: the keras.Model. |
| 290 | metrics: a nested structure of metrics objects. |
| 291 | |
| 292 | Returns: |
| 293 | A dictionary of logs. |
| 294 | """ |
| 295 | if isinstance(inputs, tuple) and len(inputs) == 2: |
| 296 | features, labels = inputs |
| 297 | else: |
| 298 | features, labels = inputs, inputs |
| 299 | outputs = self.inference_step(features, model) |
| 300 | loss = self.build_losses( |
| 301 | labels=labels, model_outputs=outputs, aux_losses=model.losses) |
| 302 | logs = {self.loss: loss} |
| 303 | if metrics: |
| 304 | self.process_metrics(metrics, labels, outputs) |
| 305 | if model.compiled_metrics: |
| 306 | self.process_compiled_metrics(model.compiled_metrics, labels, outputs) |
| 307 | logs.update({m.name: m.result() for m in metrics or []}) |
| 308 | logs.update({m.name: m.result() for m in model.metrics}) |
| 309 | return logs |
| 310 | |
| 311 | def inference_step(self, inputs, model: tf_keras.Model): |
| 312 | """Performs the forward step. |
no test coverage detected