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

Method validation_step

official/core/base_task.py:282–309  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

step_fnMethod · 0.45

Calls 6

inference_stepMethod · 0.95
build_lossesMethod · 0.95
process_metricsMethod · 0.95
updateMethod · 0.80
resultMethod · 0.45

Tested by

no test coverage detected