Calculates the loss for one input batch. Arguments: model: Model whose loss has to be calculated. inputs: Input batch data. targets: Target batch data. sample_weights: Sample weight batch data. output_loss_metrics: List of metrics that are used to aggregated output
(model,
inputs,
targets,
sample_weights=None,
output_loss_metrics=None)
| 320 | |
| 321 | |
| 322 | def test_on_batch(model, |
| 323 | inputs, |
| 324 | targets, |
| 325 | sample_weights=None, |
| 326 | output_loss_metrics=None): |
| 327 | """Calculates the loss for one input batch. |
| 328 | |
| 329 | Arguments: |
| 330 | model: Model whose loss has to be calculated. |
| 331 | inputs: Input batch data. |
| 332 | targets: Target batch data. |
| 333 | sample_weights: Sample weight batch data. |
| 334 | output_loss_metrics: List of metrics that are used to aggregated output |
| 335 | loss values. |
| 336 | |
| 337 | Returns: |
| 338 | Dict with three items: |
| 339 | 'total_loss': single tensor for overall loss, |
| 340 | 'output_losses': list of tensors for loss corresponding to each of the |
| 341 | model output. Could be a empty list when model has only one output. |
| 342 | 'metrics': list of tensors for metric specified. |
| 343 | """ |
| 344 | inputs = training_utils.cast_to_model_input_dtypes(inputs, model) |
| 345 | |
| 346 | with backend.eager_learning_phase_scope(0): |
| 347 | outs, total_loss, output_losses, masks = ( |
| 348 | _model_loss( |
| 349 | model, |
| 350 | inputs, |
| 351 | targets, |
| 352 | sample_weights=sample_weights, |
| 353 | training=False, |
| 354 | output_loss_metrics=output_loss_metrics)) |
| 355 | if not isinstance(outs, list): |
| 356 | outs = [outs] |
| 357 | metrics_results = _eager_metrics_fn( |
| 358 | model, outs, targets, sample_weights=sample_weights, masks=masks) |
| 359 | total_loss = nest.flatten(total_loss) |
| 360 | |
| 361 | return {'total_loss': total_loss, |
| 362 | 'output_losses': output_losses, |
| 363 | 'metrics': metrics_results} |
nothing calls this directly
no test coverage detected